根据文档https://developers.google.com/youtube/registering_an_application,据说为了获得令牌,我们需要发送客户端ID,可能还需要发送客户端秘密,所以我完成了代码部分BUt,当我运行代码时,令牌是空的。
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
session_start();
$OAUTH2_CLIENT_ID = 'myclientid';
$OAUTH2_CLIENT_SECRET = 'mysecreatID';
$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes('https://www.googleapis.com/auth/youtube');
$redirect = filter_var('http://youtubeupload.net/update_video.php',
FILTER_SANITIZE_URL);
$client->setRedirectUri($redirect);
echo 'token: '.$client->getAccessToken(); //No token is displayed
die();发布于 2014-05-15 20:48:53
首先,阅读有关OAuth协议的内容。
http://en.wikipedia.org/wiki/OAuth
http://oauth.net/
您首先需要一个请求令牌!
请求令牌用于访问服务器上的资源。
必须使用此请求令牌,才能将用户重定向到authorize端点!
如果用户授予您的应用程序访问权限,他将被重定向到您的回调 url,并将标记添加到该url。
如果您已经有了访问令牌,则可能需要交换它,因为它已超时。
或者,如果您有请求令牌,请将其更改为访问令牌。
通常,OAuth端点如下所示:
/oauth/request_token
/oauth/authorize
/oauth/access_tokenhttps://stackoverflow.com/questions/23677031
复制相似问题