Google OAuth2 - 使用外部生成的访问令牌 - 使用JS客户端库 [英] Google OAuth2 - Using externally generated Access Token - With JS Client Library

查看:163
本文介绍了Google OAuth2 - 使用外部生成的访问令牌 - 使用JS客户端库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的项目,我已经以服务器端方式完成了整个认证流程,将我的访问代码和令牌写入可供我的客户端应用程序使用的文本文件。

我试图使用JS CLient库中的gapi.auth.setToken()来使用这个外部生成的访问令牌授权我的应用程序。



当我最终发送请求到我需要访问的各种API时,就会出现问题。我收到此错误消息:

  {code:403,message:每日限制为未经验证的使用超出,继续使用需要注册。 ,data:Array [1],error:Object} 

这让我相信gapi。



我在这里错过了什么?

解决方案

这适用于我:

  gapi.auth.setToken({
access_token:YOUR_TOKEN_HERE
});

事实上,这个令牌对象与您在gapi.auth.authorize中获得的对象相同) 回电话。因此,如果某些内容不能按预期工作,则可以从中添加更多属性以使其正常工作。无论如何,它仍然是一个黑客,尽管它有官方文档。 。蹩脚的gapi。

For my project i have completed the entire auth flow in a server-side manner, writing my access codes and tokens to text files that can be used by my client-side application.

I am attempting to use gapi.auth.setToken() from the JS CLient Library to 'authorize' my application using this externally generated access token.

The problem occurs when i finally send requests to the various API's i need to access. i receive this error message:

{code: 403, message: "Daily Limit for Unauthenticated Use Exceeded. Continued use require signup.", data: Array[1], error: Object}

This leads me to believe that gapi.auth.setToken() is not doing what i expected it to do.

What am i missing here?

解决方案

This worked for me :

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. Anyway it's still a hack, although there is official documentation on it... Crappy gapi.

这篇关于Google OAuth2 - 使用外部生成的访问令牌 - 使用JS客户端库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆