我想使用youtube api通过此API呼叫获取用户新的订阅视频:
http://gdata.youtube.com/feeds/api/users/default/newsubscriptionvideos
如果没有登录,我会收到此回复:
User authentication required.
Error 401
如何从php登录youtube?
答案 0 :(得分:5)
您可以使用OAuth,AuthSub或ClientLogin。 ClientLogin最简单(它只使用用户名/密码),但不鼓励,因为它要求用户将凭据交给您。 AuthSub和OAuth没有。 Google的PHP library目前似乎只支持AuthSub(PHP example)和ClientLogin。
答案 1 :(得分:0)
这是一个简单的登录功能。它是返回错误消息,或成功时为0。我使用了自己的curl lib,但很明显$ this-> curl-> SetHeader可以替换为curl_setopt($ ch,CURLOPT_HTTPHEADER,$ header)
public function login(Model_ServiceAccount $account){
$this->curl->SetHeader('Content-type', 'application/x-www-form-urlencoded');
$this->curl->post('https://www.google.com/youtube/accounts/ClientLogin',
'Email=' . $account->mail->login . '&Passwd=' . $account->mail->password . '&service=youtube&source=whatever');
if (preg_match('~Error=(.+)~', $this->curl->getResponse(), $match))
return $match[1];
if (!preg_match('~Auth=(.*)~', $this->curl->getResponse(), $match)) Toolkit::error('Unhandled error in Authentication request');
$authToken = $match[1];
$this->curl->SetHeader('Authorization: GoogleLogin auth', $this->developerKey);
$this->curl->SetHeader('X-GData-Key: key=', $authToken);
$this->curl->SetHeader('Content-Type', 'application/atom+xml');
return 0;
}
答案 2 :(得分:0)