1

I'm having a hard time with getting data from YouTubeAnalytics. I have created a client and its authenticating ok (I use the same client instance for google analytics). YouTubeAnalytics is enabled in google developer console but I seem to get different responses when using the AJAX console they provide to the PHP client. My tests are;

Getting info for my channel id ("channel==MINE") - returns no data

$analytics = new Google_Service_YouTubeAnalytics($client);

var_dump($analytics->reports->query(
    "channel==MINE",
    '2014-01-01',
    '2014-08-01',
    'views', array(
        'sort' => 'day',
        'dimensions' => 'day'
    )
));

Getting info for my actual channel id ("channel==UC-CF-1aN7rEN8SBQgT9DDag") - returns 403 error

$analytics = new Google_Service_YouTubeAnalytics($client);

var_dump($analytics->reports->query(
    "channel==UC-CF-1aN7rEN8SBQgT9DDag",
    '2014-01-01',
    '2014-08-01',
    'views', array(
        'sort' => 'day',
        'dimensions' => 'day'
    )
));

Getting info for my channel - this gets a different id to my channel id

$service = new Google_Service_YouTube($client);

$channels = $service->channels->listChannels('id,brandingSettings',array(
    'mine' => 'true',
));

var_dump($channels[0]->getId());

Getting info for aforementioned different channel id - no data

var_dump($analytics->reports->query("channel=={$channels[0]->getId()}",...);

Checking on youtube for this new channel ID shows "Channel not found".

Any one have any other suggestions? It seems like it must relate to some permissions of the channel? I just don't see what the different id to my channel id is related to.

6
  • did you enable YouTube Data API V3 and YouTube Analytics in your console projects ?
    – mpgn
    Sep 8, 2014 at 19:22
  • Yes. I have tried disabling them again to confirm they are enabled ok and I get "(403) Access Not Configured" once they are disabled.
    – Matt Clegg
    Sep 8, 2014 at 19:31
  • don't understand this $channels[0]->getId(). Should be $channels["items"][0]["id] to get the id
    – mpgn
    Sep 8, 2014 at 19:42
  • $channels returns a Google_Service_YouTube_ChannelListResponse object. This class has some magic functions so you can read from ["items"] directly by using the object like an array. The problem is not related to that, I have just done it shorthand in the example for readability.
    – Matt Clegg
    Sep 8, 2014 at 19:57
  • Are you the owner of the channel? Can you check the same query with API explorer? developers.google.com/apis-explorer/#p/youtubeAnalytics/v1/… Sep 9, 2014 at 15:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.