简体   繁体   English

使用来自Java和Oauth 2.0的Google Calendar API:“权限不足”错误

[英]Using Google Calendar API fro Java and Oauth 2.0: “Insufficient Permission” error

I have an application in whick an user can login with google. 我有一个应用程序,用户可以使用谷歌登录。 Than the user during his experience into the application can choose to integrate also the GoogleCalendar service. 比用户在进入应用程序期间可以选择整合GoogleCalendar服务。 In order to achieve this my actual system works like the follow: 为了实现这一点,我的实际系统的工作方式如下:

-when the user log in with google the system store his access and refresh token and calls Google to retrive basic profile information. - 当用户使用谷歌登录时,系统会存储他的访问权限并刷新令牌,并致电Google以检索基本个人资料信息。 In order to do that I create a GoogleCalendar object using the following call: 为此,我使用以下调用创建了一个GoogleCalendar对象:

GoogleTokenResponse response = flow.newTokenRequest(code).setRedirectUri(GOOGLE_CALLBACK_URI).execute();
    GoogleCredential credential= new GoogleCredential.Builder().setJsonFactory(Constants.JSON_FACTORY)
            .setTransport(Constants.HTTP_TRANSPORT).setClientSecrets(Constants.GOOGLE_CLIENT_ID, Constants.GOOGLE_CLIENT_SECRET).build();
    credential.setAccessToken(response.getAccessToken());
    credential.setRefreshToken(response.getRefreshToken());    

-When the user choose to integrate the calendar service another Oauth iteration starts and the with a new code. - 当用户选择集成日历服务时,另一个Oauth迭代开始,并使用新代码。 I ask the GoogleCredential like before and access the service. 我像之前一样询问GoogleCredential并访问该服务。

-When the systems need to perform some operations accessing Google Calendar I create a GoogleCredential object with the following call: - 当系统需要执行访问Google日历的某些操作时,我使用以下调用创建一个GoogleCredential对象:

GoogleCredential c= new GoogleCredential.Builder().setJsonFactory(Constants.JSON_FACTORY)
            .setTransport(Constants.HTTP_TRANSPORT).setClientSecrets(Constants.GOOGLE_CLIENT_ID, Constants.GOOGLE_CLIENT_SECRET).build()
            .setAccessToken(user.getAccessToken()).setRefreshToken(user.getRefreshToken());    

Ans then ask for the service. 然后Ans要求提供服务。 But in this last case I get an error reporting 403 code and "Insufficient Permission" message. 但在最后一种情况下,我收到错误报告403代码和“权限不足”消息。

I have checked that the stored access and refresh token I set into the GoogleCredential are the same I receive the first time getting the GoogleCredential with the "code". 我已经检查过我在GoogleCredential中设置的存储访问和刷新令牌与第一次使用“代码”获取GoogleCredential时收到的相同。 I also search a lot online but no solution would work. 我也在网上搜索了很多但没有解决方案可行。 I'm really blocked into this error. 我真的被阻止了这个错误。 Thank you in advance for the help and sorry if I miss specifing something or if I make some mistake in asking the question. 提前感谢您的帮助,如果我错过了指定的内容,或者在提问时我犯了一些错误,请抱歉。

If I understand the problem you're describing correctly, incremental authorization may be what you're looking for: https://developers.google.com/accounts/docs/OAuth2WebServer#incrementalAuth 如果我理解您正确描述的问题,可能需要增量授权: https//developers.google.com/accounts/docs/OAuth2WebServer#incrementalAuth

Specifically, add include_granted_scopes=true to your authorization URLs which should cause the resulting tokens to include the sum of all so-far-granted authorizations. 具体来说,将include_granted_scopes = true添加到您的授权URL,这将导致生成的令牌包含所有迄今授予的授权的总和。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM