0
我正在使用Youtube API來嘗試一些事情,我不能在沒有得到錯誤的情況下做任何事情。預期響應代碼是200
,得到401: User authentication required
。Youtube API 401錯誤
我已驗證我的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);
任何人都知道我做錯了什麼在這裏登錄到我的帳戶?
用戶是否經歷了完整的流程(基於瀏覽器的重定向等)?另外,您是否有使用AuthSub而不是OAuth的理由? –