Youtube API:服务帐户

时间:2013-04-17 19:22:08

标签: php google-api youtube-api youtube-data-api service-accounts

我需要YouTube API的帮助。我想我必须使用service account,因为我需要超过10个用户使用相同的帐户。我不知道为什么我得到播放列表请求的空项目列表。我应该在@ developer.gserviceaccount.com和我的电子邮件之间建立一些连接。我尝试将其添加为替代电子邮件,但它已与其他Google帐户相关联。

这是我使用的代码:

const CLIENT_ID = 'xx.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = 'xx@developer.gserviceaccount.com';
const KEY_FILE = 'xx-privatekey.p12';

$client = new Google_Client();
$key = file_get_contents(__DIR__."/../../components/google-api-php-client/src/".KEY_FILE );
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(
        SERVICE_ACCOUNT_NAME,
        array('https://www.googleapis.com/auth/youtube'),
        $key)
);

$youtube = new Google_YoutubeService($client);
$playlistItemsResponse = $youtube->playlists->listPlaylists('snippet',array('mine'=>true));
var_dump($playlistItemsResponse);

这是回应:

array (size=4)
'kind' => string 'youtube#playlistListResponse' (length=28)
'etag' => string '"8TOPSm5ek9Nh6woLJrPMROQl6rM/GERGKSwb6YJY5lZXdcTaZAMM1WU"' (length=57)
'pageInfo' =>
array (size=2)
'totalResults' => int 0
'resultsPerPage' => int 5
'items' =>
array (size=0)
empty

0 个答案:

没有答案