Google YouTube Analytics API调用失败 - 401未经授权

时间:2014-04-16 15:47:21

标签: c# api youtube-data-api

我试图弄清楚前一位开发人员编写的API调用发生了什么,而且我没有取得多大进展。我已经在https://developers.google.com/youtube/analytics/v1/使用测试工具进行了测试,它返回了200,但是当从C#运行时,我得到了一个"远程服务器返回了一个错误:< 401>未授权"

致电

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

在标题中,我根据需要提供了TOKEN,但仍然没有爱。这是C#调用的片段:

        //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();

&#34; GetResponse()&#34;

失败了

任何人都知道该看什么?

0 个答案:

没有答案