问题
I am trying to use the Picker
API using this guide, and following the guide works fine.
However, my app uses Google sign-in itself to log in the user. Therefore, the auth
step in this guide is redundant, as I already have an access_token
from when the user logged in (I obtain this by exchanging the auth_code
on the server using the node js google api client lib). However, when I try to call the function setOAuthToken(oauthToken)
, using this old value of access_token, it shows me this screen rather than the Picker, asking me to log in again.
What am I doing wrong here.
回答1:
Turns out it was a scope
issue -
i wasn't updating my refresh_token
/access_token
with the new scopes granted (permissions to use drive)
setOAuthToken(access_token)
works just fine
回答2:
Maybe it's happening since you are using Google sign in (which passes the ID token generated) and Authentication API (from the guide you are using). You may refer with this thread to set it manually.
gapi.auth.setToken({ access_token: "YOUR_TOKEN_HERE" });
In fact this token object is the same as the one you get within the gapi.auth.authorize() callback. So if something doesn't works as expected, you can add more attributes from there to make it work.
Hope this helps.
来源:https://stackoverflow.com/questions/45286438/picker-api-manually-set-access-token