如何使用PHP登录Youtube?

时间:2010-05-30 10:11:25

标签: php api login youtube youtube-api

我想使用youtube api通过此API呼叫获取用户新的订阅视频:

http://gdata.youtube.com/feeds/api/users/default/newsubscriptionvideos

如果没有登录,我会收到此回复:

User authentication required.
Error 401

如何从php登录youtube?

3 个答案:

答案 0 :(得分:5)

您可以使用OAuthAuthSubClientLogin。 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)

这个适合我。使用Google帐户登录并获取登录用户频道信息。

Download Code

 $('#hall').change(