3

私はこれに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" }
4

3 に答える 3

3

サービス アカウントは YouTube API では機能しません

YouTube チャンネルが関連付けられているため、サービス アカウントは YouTube API 呼び出しでは機能しません。また、新規または既存のチャンネルをサービス アカウントに関連付けることはできません。サービス アカウントを使用して YouTube API 呼び出しを行うと、エラー タイプが無許可に設定され、理由が youtubeSignupRequired に設定されたエラーが返されます。

ソース: https://developers.google.com/youtube/v3/guides/moving_to_oauth#service_accounts

于 2014-10-17T15:56:13.760 に答える
1

OP でオフスレッドをフォローアップした後、問題は、少なくとも現時点では、さまざまな YouTube API がサービス アカウントをサポートしていないという事実に帰着します。アクセスする YouTube チャンネルに関連付けられている実際の G​​oogle アカウントの資格情報を使用して、ドキュメントに記載されているいずれかのフロー(サービス アカウント フローは含まれません) を実行する必要があります。

于 2013-01-26T02:16:40.373 に答える
0

私はそれを解決し、私の答えはここにあります: Rubyを使用してサービスアカウントを介してビデオyoutube api v3を挿入する方法お楽しみください!

あなたが得ているエラーは、映画をアップロードする電子メールに個人タグを追加しなかったためです. 私の回答のコードを使用すると、すべて解決され、機能します

于 2014-12-23T13:19:52.220 に答える