私はこれに4時間頭をぶつけているので、少し助けが必要かもしれません。
私がやりたいのは、私たちが行っているビデオコンテストのために、YouTubeにビデオを保存することです。私はサービスアカウントを介した2本足のOAuthアクセスを本当に好みます(Gmailアカウントを持っていないユーザーでもビデオを送信できるようにしたいので、これらのビデオを非公開にするか、YouTubeアカウントに非公開にします)。
しかし、それは機能しないようです。今の私のコードは次のようなものです:
function go()
{
require_once 'googleClient/Google_Client.php';
require_once 'googleClient/contrib/Google_YoutubeService.php';
define("CLIENT_ID",'xxxxxxx.apps.googleusercontent.com');
define("SERVICE_ACCOUNT_NAME",'xxxxxxx@developer.gserviceaccount.com');
define("KEY_FILE", 'googleClient/verylonghashtagprivacystuff-privatekey.p12');
define("SECRET_FILE", 'client_secrets.json');
$client = new Google_Client();
$client->setApplicationName("My Contest App");
$key = file_get_contents(KEY_FILE);
$secret = file_get_contents(SECRET_FILE);
$GAC = new Google_AssertionCredentials( SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/youtube.upload',
'https://www.googleapis.com/auth/youtube'),
$key ,'notasecret','http://oauth.net/grant_type/jwt/1.0/bearer');
$client->setAssertionCredentials($GAC);
$client::$auth->refreshTokenWithAssertion();
$client->setClientId(CLIENT_ID); // Did tried to put that one sooner
$client->setClientSecret($secret); // Did tried to put that one sooner
$json = $client->getAccessToken();
$accessToken = json_decode($json)->access_token;
$video = array();
$video["snippet"] = array();
$snippet = new Google_VideoSnippet();
$snippet->setTitle("Contest Video USERNAME");
$snippet->setDescription("Video for contest 2013 USERNAME.");
$snippet->setTags(array("Contest","Whatever","2013"));
$snippet->setCategoryId("22"); //Did tried "Entertainment".
$status = new Google_VideoStatus();
$status->setPrivacyStatus("unlisted");
$video = new Google_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$client->setAccessToken($json);
$youtube = new Google_YoutubeService($client);
$url = '/projet_video.mp4';
$response = $youtube->videos->insert(
"status,snippet",
$video,
array( 'data' => file_get_contents($url),'mimeType' => "video/*"));
//Did tried video/mp4
return $response ;}
そして結果は:
error": { "errors": [ {
"domain": "youtube.header",
"reason": "youtubeSignupRequired",
"message": "Forbidden",
"locationType": "header",
"location": "Authorization"
}], "code": 403, "message": "Forbidden" }