Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用节点js获取Twitch API的访问令牌_Javascript_Node.js_Twitch - Fatal编程技术网

Javascript 使用节点js获取Twitch API的访问令牌

Javascript 使用节点js获取Twitch API的访问令牌,javascript,node.js,twitch,Javascript,Node.js,Twitch,我正在开发一个GoogleChrome扩展,我需要在Twitch上对用户进行身份验证。根据,我注册了一个应用程序以获取客户端id,我的chrome扩展打开以下链接: https://api.twitch.tv/kraken/oauth2/authorize ?response_type=token &client_id=[your client ID] &redirect_uri=[your registered redirect URI] &am

我正在开发一个GoogleChrome扩展,我需要在Twitch上对用户进行身份验证。根据,我注册了一个应用程序以获取客户端id,我的chrome扩展打开以下链接:

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]
接受使用我的应用程序后,用户将重定向到此链接:

https://[your registered redirect URI]/#access_token=[an access token]&scope=[authorized scopes]

[您注册的重定向URI]是my node js服务器的链接。我需要保存访问令牌信息,但我不知道如何访问“#”之后的元素。请求url或其参数不包含它们。

在您发布的行下方的文档中已经有一个解释:

请注意,访问令牌位于URL片段中,而不是查询中 字符串,因此它不会显示在对服务器的HTTP请求中。统一资源定位地址 可以使用document.location.hash从JavaScript访问片段


浏览器/客户端在将请求发送到服务器之前删除片段元素。您必须加载页面,使用一个小的javascript脚本并从客户端检索值。然后您可以决定如何处理数据。例如,您可以向服务器发出ajax请求。

谢谢,我不知道我必须在客户端使用它,因此,它不起作用。@Nucktrooper页面加载上的一个小脚本,它将使用
document.location.hash
获取值,然后向您的服务中的某个启动一个请求,以便您可以存储accessToken,这将为您完成任务。如果这对你有帮助,你可以接受答案:)