Youtube API : Service account

核能气质少年 提交于 2019-12-12 11:46:19

问题


I need help for YouTube API. I guess that I have to use service account because I need more then 10 users use same account. I am not sure why I get empty items list for playlists request. Should I create some connection between @developer.gserviceaccount.com and my e-mail. I try to add it as alternative e-mail but it is already associated with another Google Account.

This is code i used:

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);

And this is response:

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

来源:https://stackoverflow.com/questions/16068433/youtube-api-service-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!