3

我正在尝试连接到 Google Analytics 报告 API 以获取基本的综合浏览量统计信息。我正在尝试遵循本教程(http://www.arboundy.com/2012/04/getting-started-with-google-analytics-in-c/)。我无法设置正确的位来获得成功的身份验证,因为谷歌最近似乎对 API 进行了很多更改,因此原始配置似乎不起作用。

这是我目前拥有的:

        Service = new AnalyticsService("MyDemoApp");
        Service.setUserCredentials("user@gmail.com", "password");

        AccountQuery AccountsQuery = new AccountQuery("https://www.googleapis.com/analytics/v3/data/ga"/*Not sure what goes here this gives a 400*/);
        AccountFeed AccountsFeed = Service.Query(AccountsQuery); // 400 error here

任何想法如何通过 V3 api 连接到这个(这似乎是我从 NuGet 得到的)

4

1 回答 1

3

这必须在 c# 中为你工作。(我已经尝试过并且工作过)

    string username = "youremailuser@domain.com";
    string pass = "yourpassword";
    string gkey = "?key=YourAPIkEY";

    string dataFeedUrl = "https://www.google.com/analytics/feeds/data" + gkey;
    string accountFeedUrl = "https://www.googleapis.com/analytics/v2.4/management/accounts" + gkey;

    AnalyticsService service = new AnalyticsService("WebApp");
    service.setUserCredentials(username, pass);

    DataQuery query1 = new DataQuery(dataFeedUrl);


    query1.Ids = "ga:12345678";
    query1.Metrics = "ga:visits";
    query1.Sort = "ga:visits";

    query1.GAStartDate = new DateTime(2012, 1, 2).ToString("yyyy-MM-dd"); 
    query1.GAEndDate = DateTime.Now.ToString("yyyy-MM-dd");
    query1.StartIndex = 1;        

    DataFeed dataFeedVisits = service.Query(query1);

    foreach (DataEntry entry in dataFeedVisits.Entries)
    {
        string st = entry.Title.Text;
        string ss = entry.Metrics[0].Value;
        visits = ss;
    }

了解更多详情从 Google 数据 API 读取数据

于 2013-02-15T03:28:32.980 回答