2013-01-23 82 views
3

我在这个4小时内敲打我的头,所以我可能需要一点帮助。PHP中的YouTube数据API v3帐户服务:403 - 禁止:YoutubeSignupRequired

我想要做的就是在YouTube上存储视频,我们正在参加视频竞赛。我真的更喜欢通过服务帐户进行双方的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",'[email protected]'); 
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" } 
+0

。 – user2004005

+0

我很确定这是相同的东西,回答在http://stackoverflow.com/questions/14453505/youtube-data-api-v3-video-upload-403-forbidden-youtubesignuprequired –

+0

非常感谢回答我们。我认为最好自己提出问题,因为他没有提供太多的代码,而且我们似乎使用不同的语言。 我会尝试给你的答案,尽快发布反馈。 但是这很奇怪。我用来创建客户端API ID的Google帐户,以及这些东西(API ON等)是我们用来发布视频到YouTube的那个。我以为它以某种方式连接在一起。 谢谢 – user2004005

回答

1

跟进关闭线程与OP后,问题归结为一个事实,即不同的YouTube API不支持服务帐户,至少目前没有。您需要使用与您要访问的YouTube频道相关联的实际Google帐户的凭证,通过其中一个流程described in the docs(其中不包括服务帐户流程)。

+0

您会如何得出该结论?我问,因为可以选择在服务中启用“YouTube Data API v3”。 – Draven

+0

您可以为任何API控制台项目启用YouTube Data API v3。这与您在浏览OAuth 2流程时需要使用的帐户正交。 YouTube现在不支持服务帐户 - 这就是事情的方式。 –

+0

YouTube有什么想法支持服务帐户?我们真的想升级到V3,但不能,因为我们需要服务帐户功能。 – sanjosep43

3

服务帐户不使用YouTube API工作

服务帐户不YouTube的API调用,因为相关的YouTube频道工作,你不能用服务帐户新的或现有的通道相关联。使用服务帐户进行YouTube API调用将返回错误,并将错误类型设置为未经授权,并将原因设置为youtubeSignupRequired。

来源:https://developers.google.com/youtube/v3/guides/moving_to_oauth#service_accounts

0

我解决了它,我的答案就在这里:How to insert video youtube api v3 through service account with ruby享受!

您收到的错误是因为您没有添加带电子邮件的人员标签以上传影片。如果我添加“onBehalfOfContentOwner”,我得到了一个全新的错误500,没有错误文本(空),所以这一切都解决了,并工作,如果你使用我的回答中的代码

相关问题