在要求C#-Execution谷歌Analytics(分析)API失败:https://www.google.com/analytics/feeds/accounts/default [英] Google Analytics API in C# -Execution of request failed: https://www.google.com/analytics/feeds/accounts/default

查看:469
本文介绍了在要求C#-Execution谷歌Analytics(分析)API失败:https://www.google.com/analytics/feeds/accounts/default的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要访问谷歌分析数据,我得到了来自谷歌数据API SDK样本。但这些编码不工作,并抛出异常。




请求执行失败:的 https://www.google.com/analytics/feeds/accounts/default




让我找到了这样做的原因是谷歌更新它到V3.0。我搜索了C#最新的编码,但我无法找到这个解决方案。



我有同样的问题,因为这一点,但用C#。
异常使用的GData .NET分析API



我试着做如下改变,因为它在谷歌开发人员表示编码 - 的 https://developers.google.com/analytics/resources/articles/gdata-migration-guide#appendix_a

 字符串username = this.Username.Text; 
字符串密码= this.Password.Text;

AnalyticsService服务=新AnalyticsService(AnalyticsSampleApp);
service.setUserCredentials(用户名,密码);
串googleAccountWebId =AIXXXXXXXXXXXXXXXXXXXXXXXXXXX;
串profileFeedUrl =https://www.googleapis.com/analytics/v2.4/data?key=+ googleAccountWebId;

DataQuery QUERY2 =新DataQuery(profileFeedUrl);
query2.Ids =12345678;
query2.Metrics =GA:访问;
query2.Sort =GA:访问;
query2.GAStartDate = DateTime.Now.AddMonths(-1).AddDays(-2)的ToString(2011-08-01);
query2.GAEndDate = DateTime.Now.ToString(2013年9月1日);
query2.StartIndex = 1;


数据传送专线数据= service.Query(QUERY2);


的foreach(在data.Entries DataEntry项)
{
串ST = entry.Metrics [0] .value的;
}



但即使我改变这一点,在

$ B $抛出异常b

数据传送专线数据= service.Query(QUERY2);




这行。例外情况如下:




请求执行失败:的 https://www.googleapis.com/analytics/v2.4/data?key=AIXXXXXXXXXXXXXXXXXXXXXX-8&start-index=1&end-date=2013-09-01&ids = 12345678&安培;指标= GA:探访&安培;排序= GA:探访&功放;启动日期= 2011-08-01




我使用以下DLL

  Google.GData.Analytics.dll 
$ Google.GData.Client.dll b $ b Google.GData.Extensions.dll

我的问题:




  1. 我怎样才能纠正这种错误?


  2. 如何我可以访问谷歌分析数据?它是否正确?不然有什么办法做?
    的例子我想获得可用的配置文件ID和它们的值。 (标题和页面浏览量)



解决方案

Analytics(分析)帐户:



我假设你有一个Analytics帐户已如果你不然后创建一个,在这里注册您的域名:
http://www.google.com/intl/en/analytics/



为了让您的API密钥做到这一点:



请按照上的https://developers.google.com/analytics/resources/articles/gdata-migration-guide (创建于谷歌的API项目控制台)来生成密钥一旦你把它设置为查询字符串,要求谷歌分析服务的一部分,在这种情况下:
YourAPIkEStringabcdefghijklmno



若要获取配置文件ID(IDS上的代码),你应该这样做:



登录到您的Analytics帐户,选择清单上所需的域(链接),点击管理员按钮和配置文件选项卡中找到配置文件
配置子选项卡,在那里你会发现在这种情况下,配置文件ID的八个字符ID:
12345678



这里有一些C#代码,以帮助您获得该ID访问的次数:

 公共字符串VisitsNumber()
{
串访问=的String.Empty;
字符串的用户名=youremailuser@domain.com;
字符串传递=你的密码;
串gkey =键= YourAPIkEYYourAPIkEYYourAPIkEYYourAPIkE?

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

AnalyticsService服务=新AnalyticsService(Web应用程序);
service.setUserCredentials(用户名,PASS);

DataQuery QUERY1 =新DataQuery(dataFeedUrl);

query1.Ids​​ =GA:12345678;
query1.Metrics =GA:访问;
query1.Sort =GA:访问;

//你被设置2013年9月1日,并因为它尚未达到,一定要设置有效的日期
//开始日期是更好的那一个无效的日期放置aprox的日期,当你注册了谷歌分析,例如2012年1月2日的域,结束日期的实际日期就足够了,没有必要去进一步
query1.GAStartDate =新日期时间(2012年1,2)的ToString(YYYY-MM-DD);
query1.GAEndDate = DateTime.Now.ToString(YYYY-MM-DD);
query1.StartIndex = 1;

数据传送专线dataFeedVisits = service.Query(QUERY1);

的foreach(在dataFeedVisits.Entries DataEntry项)
{
串ST = entry.Title.Text;
串SS = entry.Metrics [0] .value的;
访问= SS;
}

回访;
}

保护无效的Page_Load(对象发件人,EventArgs五)
{
如果(!Page.IsPostBack)
{
响应。写(访问:+ this.VisitsNumber());
}
}



由于2.4 API不那么灵活了,我这里有另一篇文章黑客它来获取配置文件ID:
获取使用的GData .NET分析API 2.4 注册帐户的具体配置文件ID,如果你需要将代码到C#,你可以使用Telerik的转换器,转换:的 http://converter.telerik.com/



我想这足以使用2.4 API。如果你需要额外的帮助让我知道。


i want to access Google analytic data and i got samples from Google data API SDK. but these coding does not working and throws exception

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

so i found the reason for this is Google updated it's to v3.0. i searched updated coding for the C#, but i couldn't find solution for this.

i have same problem as this, but with C#. Exception thrown when using GData .NET Analytics API

i tried coding with doing changes as follows as it says in Google developer - https://developers.google.com/analytics/resources/articles/gdata-migration-guide#appendix_a

string userName = this.Username.Text;
string passWord = this.Password.Text;

AnalyticsService service = new AnalyticsService("AnalyticsSampleApp");
service.setUserCredentials(userName, passWord);
string googleAccountWebId = "AIXXXXXXXXXXXXXXXXXXXXXXXXXXX";
string profileFeedUrl = "https://www.googleapis.com/analytics/v2.4/data?key=" + googleAccountWebId;

DataQuery query2 = new DataQuery(profileFeedUrl);
query2.Ids = "12345678";
query2.Metrics = "ga:visits";
query2.Sort = "ga:visits";
query2.GAStartDate = DateTime.Now.AddMonths(-1).AddDays(-2).ToString("2011-08-01");
query2.GAEndDate = DateTime.Now.ToString("2013-09-01");
query2.StartIndex = 1;


DataFeed data = service.Query(query2);


foreach (DataEntry entry in data.Entries)
{
    string st=entry.Metrics[0].Value;       
}

but even i change this it throws exception in

DataFeed data = service.Query(query2);

this line. exception is as follows:

Execution of request failed: https://www.googleapis.com/analytics/v2.4/data?key=AIXXXXXXXXXXXXXXXXXXXXXX-8&start-index=1&end-date=2013-09-01&ids=12345678&metrics=ga:visits&sort=ga:visits&start-date=2011-08-01

i'm using following DLL

Google.GData.Analytics.dll
Google.GData.Client.dll
Google.GData.Extensions.dll

My Questions :

  1. how can i correct this error?

  2. how can i access Google analytic data? is this correct? or else what is the way to doing it?? for a example i want to get available ProfileId and their values. (Title and Page views)

解决方案

Analytics Account:

I am assuming you have an analytics account already if you don't then create one, and sign up your domain here: http://www.google.com/intl/en/analytics/

To get your API Key do this:

Follow the instructions on https://developers.google.com/analytics/resources/articles/gdata-migration-guide (Create a Project in the Google APIs Console) to generate your key Once you have it set it as part of the querystring to request to Google Analytics service, in this case: YourAPIkEStringabcdefghijklmno

To get the profileId (Ids on the code) you should do this:

Log into your analytics account, select the desired domain on your list (blue link) click on the administrator button and on the profiles tab find the profile configuration subtab, right there you will find the profile id in this case the eight characters long id: 12345678

Here you have some C# code to help you getting the number of visits for that Id:

public string VisitsNumber() 
    {
        string visits = string.Empty;
        string username = "youremailuser@domain.com";
        string pass = "yourpassword";
        string gkey = "?key=YourAPIkEYYourAPIkEYYourAPIkEYYourAPIkE";

    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";

    //You were setting 2013-09-01 and thats an invalid date because it hasn't been reached yet, be sure you set valid dates
    //For start date is better to place an aprox date when you registered the domain on Google Analytics for example January 2nd 2012, for an end date the actual date is enough, no need to go further
    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;
    }

    return visits;
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack) 
    {
        Response.Write("Visits:" + this.VisitsNumber());
    }
}

Since the 2.4 API is not so flexible anymore, I have another post here hacking it to get the profile Id: Getting an specific ProfileId from registered Accounts using GData .NET Analytics API 2.4 if you need to convert the code to C# you can use the Telerik converter: http://converter.telerik.com/

I think this suffice to use the 2.4 API. If you need extra help let me know.

这篇关于在要求C#-Execution谷歌Analytics(分析)API失败:https://www.google.com/analytics/feeds/accounts/default的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆