使用节点 js 取回 Twitch API 的访问令牌
Get back Access Token of Twitch API with node js
我正在开发一个 google chrome 扩展程序,我需要在其中对 Twitch 上的用户进行身份验证。根据 https://github.com/justintv/Twitch-API/blob/master/authentication.md,我注册了一个申请以获得 client_id 并且我的 chrome 扩展打开了以下 link:
https://api.twitch.tv/kraken/oauth2/authorize
?response_type=token
&client_id=[your client ID]
&redirect_uri=[your registered redirect URI]
&scope=[space separated list of scopes]
接受使用我的应用程序后,用户将被重定向到此 link:
https://[your registered redirect URI]/#access_token=[an access token]&scope=[authorized scopes]
[你注册的重定向 URI] 是我的节点 js 服务器的 link。我需要保存access_token信息,但我不知道如何访问'#'后的元素。请求 url 或其参数不包含它们。
在您发布的行下方的文档中已经有解释:
Note that the access token is in the URL fragment, not the query
string, so it won't show up in HTTP requests to your server. URL
fragments can be accessed from JavaScript with document.location.hash
browser/client 在向服务器发送请求之前删除片段元素。您必须加载页面,有一个小的 javascript 脚本并从客户端检索值。然后您可以决定如何处理数据。例如,您可以向服务器发出 ajax 请求。
我正在开发一个 google chrome 扩展程序,我需要在其中对 Twitch 上的用户进行身份验证。根据 https://github.com/justintv/Twitch-API/blob/master/authentication.md,我注册了一个申请以获得 client_id 并且我的 chrome 扩展打开了以下 link:
https://api.twitch.tv/kraken/oauth2/authorize
?response_type=token
&client_id=[your client ID]
&redirect_uri=[your registered redirect URI]
&scope=[space separated list of scopes]
接受使用我的应用程序后,用户将被重定向到此 link:
https://[your registered redirect URI]/#access_token=[an access token]&scope=[authorized scopes]
[你注册的重定向 URI] 是我的节点 js 服务器的 link。我需要保存access_token信息,但我不知道如何访问'#'后的元素。请求 url 或其参数不包含它们。
在您发布的行下方的文档中已经有解释:
Note that the access token is in the URL fragment, not the query string, so it won't show up in HTTP requests to your server. URL fragments can be accessed from JavaScript with document.location.hash
browser/client 在向服务器发送请求之前删除片段元素。您必须加载页面,有一个小的 javascript 脚本并从客户端检索值。然后您可以决定如何处理数据。例如,您可以向服务器发出 ajax 请求。