1

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

网址如下所示:

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

4

1 回答 1

0

使用 javascript,从浏览器位置栏中获取 URL 数据:如果它包含例如以下 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 = 文档.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
于 2013-09-11T16:19:01.573 回答