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