Youtube Data API v3 PHP Account Service: 403 - Forbidden: YoutubeSignupRequired

I've been banging my head about this for 4 hours now so I might need a little help.

What I want to do is store the video on YouTube, for the video contest we have. I really prefer two-legged OAuth access via a service account (I want users even without a gmail account to be able to send videos to us, and I want to put those videos private or unregistered in our YouTube account).

But it doesn't seem to work. My code right now looks something like this:

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

      

And the result:

error": {  "errors": [   {
    "domain": "youtube.header",
    "reason": "youtubeSignupRequired",
    "message": "Forbidden",
    "locationType": "header",
    "location": "Authorization"
}], "code": 403,  "message": "Forbidden" }

      

+3


source to share


3 answers


Service accounts don't work with YouTube API

Service accounts do not work for YouTube API calls because they are associated with a YouTube channel and you cannot associate new or existing channels with service accounts. Using a service account to call YouTube API calls will result in an error stating the error type set for unauthorized access and the reasons set for youtubeSignupRequired.



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

+3


source


After you do non-threaded communication with the OP, the problem comes down to the fact that various YouTube APIs don't support service accounts, at least not at this time. You need to go through one of the streams described in the docs (which does not include the service account stream) using the credentials of the actual Google Account associated with the YouTube channel you want to access.



+1


source


I decided this, and my answer here: How to insert video youtube api v3 through the service account with ruby Enjoy!

The error you are getting is that you have not added the person tag with the email address to download the movie. This is all solved and works if you use the code in your answer

0


source







All Articles