GMail REST API: Using Google Credentials Without I

2019-01-19 05:32发布

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条回答
Evening l夕情丶
2楼-- · 2019-01-19 06:03

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.

查看更多
登录 后发表回答