1
votes

Uploading videos to a YouTube account without a channel fails.

I'm using the YouTube Data API (Version 3) and the Google APIs Client Library for PHP to upload custom videos to a users channel. The user has given authorization (via OAuth2) to manage their YouTube account, but it's possible that the user has never created a YouTube channel.

The question is: How do I check if the user has a valid channel before trying to start an upload? Ideally, I'd want to check right after authentication.

2

2 Answers

2
votes

After a valid oAuth token is received, you can make the following call (this assumes that '$youtube' represents your Google_YoutubeService object):

$channelsResponse = $youtube->channels->listChannels('contentDetails', array(
      'mine' => 'true',
    ));

If $channelsResponse['items'] is empty, then the authenticated user has no channels.

0
votes

http get calls for 'https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&key={}&access_token={}' will return items even if the user does not has channels.

an example response is:

{u'etag': u'"IHLB7Mi__JPvvG2zLQWweA"',
 u'items': [{u'contentDetails': {u'googlePlusUserId': u'107123',
    u'relatedPlaylists': {u'favorites': u'FLMZmB78WMw',
     u'likes': u'LLMZmB78we',
     u'uploads': u'UUMZmB78Wwef',
     u'watchHistory': u'HLMZmB78Wwe',
     u'watchLater': u'WLMZmB78WMDgwef'}},
   u'etag': u'"IHLB7Mi__JPvvG2zLQWAg8l36"',
   u'id': u'UCMZmB78WMD',
   u'kind': u'youtube#channel'}],
 u'kind': u'youtube#channelListResponse',
 u'pageInfo': {u'resultsPerPage': 1, u'totalResults': 1}}

in case that 'googlePlusUserId' is in response, then the user has channel.