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

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

问题描述

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

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.

我正在尝试使用 JS 客户端库中的 gapi.auth.setToken() 来使用这个外部生成的访问令牌授权"我的应用程序.

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

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

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}

这让我相信 gapi.auth.setToken() 没有按照我的预期去做.

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

我在这里遗漏了什么?

推荐答案

这对我有用:

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

事实上,这个令牌对象和你在 gapi.auth.authorize() 回调中得到的那个对象是一样的.因此,如果某些内容没有按预期工作,您可以从那里添加更多属性以使其工作.无论如何,它仍然是一个 hack,尽管它有 官方文档.. 蹩脚的gapi.

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天全站免登陆