更新了Google Analytic API和旧版本

时间:2012-09-24 09:22:44

标签: asp.net google-analytics google-api

在Google Analytic Update之前,api此代码有效。

    string userName = GAEmailAddress.ToString();//Its From Database
    string passWord = GAPassword.ToString();//Its From Database

    const string dataFeedUrl = "https://www.google.com/analytics/feeds/data";


    AccountQuery query = new AccountQuery();
    AnalyticsService service = new AnalyticsService("AnalyticsApp");
    if (!string.IsNullOrEmpty(userName))
    {
        service.setUserCredentials(userName, passWord);
    }
    string str = "";
    try
    {
        AccountFeed accountFeed = service.Query(query);
        foreach (AccountEntry entry in accountFeed.Entries)
        {
            str = entry.ProfileId.Value;
        }

        DataQuery query1 = new DataQuery(dataFeedUrl);
        // Bounce Rate Calculations
        query1.Ids = str;
        query1.Metrics = "ga:visits,ga:bounces";//visitors
        query1.Sort = "ga:visits";
        query1.GAStartDate = DateTime.Now.AddMonths(-1).AddDays(-2).ToString("yyyy-MM-dd");
        query1.GAEndDate = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd");
        query1.StartIndex = 1;

  //Others code and other data for bound

我搜索SO并找到此链接。

gapi account data url goes to 404

我替换了这个链接:

const string dataFeedUrl = "https://www.google.com/analytics/feeds/data";

使用:

https://www.googleapis.com/analytics/v2.4/management/accounts?start-index=1&max-results=100&key=API_KEY

但我仍然得到错误:

Execution of request failed: https://www.google.com/analytics/feeds/accounts/default

我仍在搜索并找到此链接:

https://developers.google.com/analytics/devguides/reporting/core/v2/#register

正如链接所说,我更换:

https://www.googleapis.com/analytics/v2.4/data

但我还是有错误吗?我在这里缺少什么?感谢。

0 个答案:

没有答案