GMail REST API: Using Google Credentials Without Impersonate

試著忘記壹切 提交于 2019-11-27 06:16:33

问题


Is it possible to use Google Credentials for GMAIL REST API without using impersonation??

In many examples of GMAIL REST API i see is mandatory to use an impersonation account associated to a domain and Google APPS. I just want to use GMAIL REST API api server-to-server :

f.e:

GoogleCredential  credential = new GoogleCredential.Builder().setTransport(httpTransport)
            .setJsonFactory(jsonFactory)
                         .setServiceAccountId(serviceAccountUserEmail)
                         **.setServiceAccountUser("myuser@mydomain.com)**
                         .setServiceAccountScopes(SCOPES)
                         .setServiceAccountPrivateKeyFromP12File(
                         new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))                                
                        .build();

The matter is that i don't have any domain and i use just a GMAIL account...but i don't get any way to authorize, for example : MyMainGmailAcccoun@gmail.com

The servive acccount id 4xxxxxxxxxxxxxq@developer.gserviceaccount.com"; is a "client account" created with the MyMainGmailAcccoun@gmail.com

This has no sense , i don't want to impersonate with no other account of another domain, and i don't get any way to authozize MyMainGmailAcccoun@gmail.com .

Just only works, if you have an account to impersonate of other domain associated with Google Apps, and to get Google Apps...you need a domain.

Any advise??


回答1:


You may just want to simply use OAuth 2.0 for Web Server Applications. Assuming you want the authorization for more than an hour, you can use refresh tokens.



来源:https://stackoverflow.com/questions/29341096/gmail-rest-api-using-google-credentials-without-impersonate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!