Picker API - manually set access_token

社会主义新天地 提交于 2021-02-07 10:21:29

问题


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.

image

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

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