Google api 调用gapi.auth.authorize()返回空的访问令牌
调用Google api 调用gapi.auth.authorize()返回空的访问令牌,google-api,google-drive-api,google-api-client,Google Api,Google Drive Api,Google Api Client,调用gapi.auth.authorize()并通过此命令在服务器端获取访问令牌后: gapi.auth.authorize({ response_type: 'code', client_id: "client_id", immediate : false, access_type : 'offline', scope: "scopes", redirect_uri : "redirect_uri"} , handleAuth1); 我再次调用它以在客户端接收令牌: gapi.auth.au
gapi.auth.authorize()
并通过此命令在服务器端获取访问令牌后:
gapi.auth.authorize({ response_type: 'code', client_id: "client_id", immediate : false, access_type : 'offline', scope: "scopes", redirect_uri : "redirect_uri"} , handleAuth1);
我再次调用它以在客户端接收令牌:
gapi.auth.authorize({client_id: "client_id", immediate : true, scope: "scopes"}, handleAuth2);
出于某种原因,handleAuth2会得到一个没有访问令牌的结果。在这种情况下,我的应用程序要求用户允许第二次访问。在这种情况下,谷歌显示“有离线访问”是因为新的政策
我可以同时获得脱机和联机权限吗
编辑:在google添加这个新API时,我使用gapi.auth.sign()修复了这个问题。诀窍是首先使用以下参数调用api:
<span id="signinButton">
<span
class="g-signin"
data-callback="loginFinished"
data-clientid="808248997275-ol6kol8h23j018iug3d5odi9vhrja9j5.apps.googleusercontent.com"
data-accesstype="offline"
data-cookiepolicy="http://brif.us"
data-scope="profile https://mail.google.com https://www.google.com/m8/feeds https://www.googleapis.com/auth/drive">
</span>
使用接受的代码在服务器端生成刷新令牌。
下一次调用应省略脱机行,因此代码应为:
<span id="signinButton">
<span
class="g-signin"
data-callback="loginFinished"
data-clientid="808248997275-ol6kol8h23j018iug3d5odi9vhrja9j5.apps.googleusercontent.com"
data-cookiepolicy="http://brif.us"
data-scope="profile https://mail.google.com https://www.google.com/m8/feeds https://www.googleapis.com/auth/drive">
</span>
希望这对某人有帮助