Google YouTube Analytics API Call Fail - 401 Unauthorized

110 views
Skip to first unread message

Jay

unread,
Apr 16, 2014, 6:51:01 PM4/16/14
to google-analytics...@googlegroups.com
I'm trying to figure out what is happening to a API call written by a previous developer, and I'm not making much progress. I've tested using the test harness at https://developers.google.com/youtube/analytics/v1/and it returns a 200.

When running from C# Visual Studio project, I get a "The remote server returned an error: <401> Unauthorized"

URL CALL:
https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3D<OUR CHANNELID>&start-date=2014-03-24&end-date=2014-04-11&metrics=views,uniques,subscribersGained,subscribersLost,comments,favoritesAdded,favoritesRemoved,likes,dislikes,shares&access_token=<OUR TOKEN>&alt=csv&dimensions=7DayTotals

C# CODE:

        //Create URL for Google API Call
        string youTubeEndpoint = @"https://www.googleapis.com/youtube/analytics/v1/reports" +
        "?ids=channel%3D%3D" + <CHANNEL ID> +
        "&start-date=" + startDateString +
        "&end-date=" + endDateString +
        "&metrics=" + report.Metrics +
        "&access_token=" + <TOKEN>+
        "&alt=csv" +
        "&dimensions=" + report.Dimensions;

        //Create HTTP Request
        HttpWebRequest trident = (HttpWebRequest)WebRequest.Create(youTubeEndpoint);

        //Add Required Header with Auth Token
        trident.Headers.Add("Authorization", "Bearer " + <TOKEN>);

        //Call and Return Results From Google
        return trident.GetResponse();

As you can see, I'm adding the OAuth token in the header

I'm really out of ideas what's wrong. The error returning doesn't give me much to go on. I've regenerated my access token several times. Also, this was working and suddenly stopped without any change on our end.

Any ideas?
Jay

Jay

unread,
Apr 21, 2014, 1:38:50 PM4/21/14
to google-analytics...@googlegroups.com
Soooo, I'm guessing this forum is kind of a ghost town?

chris@shufflepoint

unread,
Apr 22, 2014, 1:27:23 PM4/22/14
to google-analytics...@googlegroups.com
Hi Jay,
Your question likely confused the folks here since this is the GA API forum but you are asking about the YouTube api.
My recommendation is to compare you request with the URL you see in the Google API Explorer - which you said works. If you still can't figure out the difference then report back here.

 - Chris
Reply all
Reply to author
Forward
0 new messages