从URL提取访问密钥 - YouTube API

时间:2013-09-11 14:29:20

标签: youtube-api token

我已向YouTube API发送了访问令牌请求,一旦用户授予对应用程序的访问权限,然后将其重定向回页面,我可以在URL中看到访问令牌设置为到期 - 我的问题是如何从URL中提取并将访问密钥存储在变量中?

网址如下:

http://site.com/wp-admin/admin.php?page=uploader/#access_token=token-here&token_type=Bearer&expires_in=3600

1 个答案:

答案 0 :(得分:0)

使用javascript从浏览器位置栏获取网址数据: 如果它包含例如以下URL http://site.com/wp-admin/admin.php?page=wp2yt_uploader/#access_token=token-here&token_type=Bearer&expires_in=3600

在chrome,FireFox和Internet Explorer中。

var urlUsed = document.URL;

var p = window.location.protocol;

var h = window.location.host;

var pa = window.location.pathname;

var s = window.location.search;

urlUsed == http://site.com/wp-admin/admin.php?page=wp2yt_uploader/#access_token=token-here&token_type=Bearer&expires_in=3600

p == http:

h == site.com

pa == /wp-admin/admin.php

s == ?page=wp2yt_uploader/#access_token=token-here&token_type=Bearer&expires_in=3600