Martyn
Martyn

Reputation: 6403

YouTube API - how to specify which channel to upload to

We have a script that uploads videos to YouTube that have been uploaded to our server previously. It's a rather large script so I'll try and be quite concise. The code that is attempting the upload...

$video = ... // our model instance, as we queue videos in a db table
$media = new Google_Http_MediaFileUpload(...
.
.
.
$fp = fopen($videoFile, 'rb');
while (!$status && !feof($fp)) {
    $chunk = fread($fp, $chunkSize);
    $status = $media->nextChunk($chunk);

    $video->progress = $media->getProgress();
    $video->save();
}
fclose($fp);
$fp = null;

$client->setDefer(false);

...is getting the following error from the YouTube API:

0: Failed to start the resumable upload (HTTP 401: youtube.header, Unauthorized)

From what I can see, our script is working as it should. It gets the access token, everything up until this point where it's attempting to upload the file seems fine. But then it gets the following error back from YouTube and then handles the error as designed.

According to this SO post, the reason for this error is that a channel doesn't exist for this account who issues the OAuth/API credentials.

YouTube API3.0 videos.insert (upload) -- "Failed to start the resumable upload" exception

.. although this account that owns the credentials isn't the owner of the target channel, it is a manager of that channel. Bit of a perplex setup I know but this has been the setup for a number of years and the credentials haven't changed, only our software to a newer version. As the account that issues the oauth credentials is a manager of the target channel, is it just a case of specifying which channel to upload to? e.g. channels that account owns/manages. I can't see anything that specifies this in the previous version either, but I'm wondering if it's something that should be there anyway.

Upvotes: 1

Views: 2213

Answers (1)

goblin
goblin

Reputation: 1553

Uploading a video on behalf of a content owner is not allowed for a standard google account that is the reason why you are getting unauthorized response. In order to do this you should first transfer of ownership of the account but this should be done by the owner himself. (as stated in the support page)

Quoted below are the steps on how you can do this.

Each Google+ page has one owner; this owner applies to the connected YouTube channel. To transfer ownership of a channel connected to a Google+ page, you need to transfer ownership of the page itself. The person you transfer ownership to must be a manager of the page for at least one day.

  1. Only the current owner can transfer ownership. Sign in to the page owner Google Account.

  2. On YouTube, make sure you pick the right channel. Then go to the channel's account settings and click Add or remove managers.

  3. Click the dropdown arrow below the person's name and select Transfer ownership.

Upvotes: 3

Related Questions