OAuth Token works for userInfo but not to Google C

2019-08-30 02:47发布

问题:

Can someone tell me why I can't use the same token to retrieve userInfo and calendars list from Google?

I have set the correct scopes (I think):

  private static final String PLUS_ME_SCOPE = "https://www.googleapis.com/auth/plus.me";
  private static final String USER_INFO_PROFILE_SCOPE = "https://www.googleapis.com/auth/userinfo.profile";
  private static final String USER_INFO_EMAIL_SCOPE = "https://www.googleapis.com/auth/userinfo.email";
  private static final String GOOGLE_CALENDAR_SCOPE = "https://www.googleapis.com/auth/calendar";

To get the user info I use this url: https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token= and for calendars I use: https://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=writer&key= .

In user Info I get all the correct info but for the calendar I get Error 401 : Login Required.

What's wrong in here?

回答1:

Change

https://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=writer&key=

to

https://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=writer&access_token=

Just that simple ;)

UPDATE:

Also note, that it is not recommended to specify the access token as a query parameter:

Because of the security weaknesses associated with the URI method (see Section 5), including the high likelihood that the URL containing the access token will be logged, it SHOULD NOT be used unless it is impossible to transport the access token in the "Authorization" request header field or the HTTP request entity-body.