NullPointerException only after I have setServiceAccountUser() for GoogleCredential object (Grails/Java)

我怕爱的太早我们不能终老 提交于 2019-12-04 04:01:31

I discovered the reason for the behaviour we were experiencing, but thanks for your suggestions, none-the-less, user1807337 & Srinivasan.

We need to get our application's users to delegate domain-wide authority to our application. This can be done by the organisataion's google apps admin, following the instructions in the sub-section entitled Delegating domain-wide authority to the service account

https://developers.google.com/accounts/docs/OAuth2ServiceAccount

Here is the explanation given in the same resource: "If you have delegated domain-wide access to the service account and you want to impersonate a user account, specify the email address of the user account with the setServiceAccountUser method of the GoogleCredential factory..."

Try this

'com.google.api.client.googleapis.auth.oauth2.GoogleCredential.Builder credential_origine_builder = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
                .setJsonFactory(JSON_FACTORY)
                .setServiceAccountId("[[]]")
                .setServiceAccountScopes(GOOGLE_TASK_SCOPES)
                .setServiceAccountPrivateKeyFromP12File(new File("cfg/file.p12"));

credential_origine_builder.setServiceAccountUser("user@domain.com");'

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