Youtube API 401错误

时间:2013-01-22 17:33:52

标签: php youtube-api

我正在使用Youtube API尝试一些事情,如果不收到错误,我就无法做任何事情。预期回复代码为200,已获得401: User authentication required

我已经验证了我的Youtube频道

session_start();

$clientLibraryPath = 'Youtube/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);


require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt = new Zend_Gdata_YouTube();
Zend_Loader::loadClass('Zend_Gdata_AuthSub');

function getAuthSubRequestUrl()
{
$next = 'LINK';
$scope = 'http://gdata.youtube.com';
$secure = false;
$session = true;
return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
}

function getAuthSubHttpClient()
{
if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
    echo '<a href="' . getAuthSubRequestUrl() . '">Login!</a>';
    return;
} else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
  $_SESSION['sessionToken'] =   Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);

}

$httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
return $httpClient;
}
getAuthSubHttpClient();

$cID = "Client ID";
$aID = "App ID";
$dK = "DEV KEY"; // Hidden
$yt = new Zend_Gdata_YouTube($httpClient, $aID, $cID, $dK);

任何人都知道我在这里登录我的帐户有什么问题吗?

1 个答案:

答案 0 :(得分:0)

确保您的代码托管在您在Google Code Console

中设置的完全相同的网址中

如果您的javascript origins设置为http://example.com,请确保您的代码未在http://example.com/somethinghttp://something.example.com托管!这似乎对我有用:)