2011-02-15 94 views
9

Hy guys,我们正在开发一个系统,可以让用户访问Google Analytics。我试图以这样的方式实现它,所以用户不需要在我们的网站上输入他们的Google登录凭据,所以试图使用他们的登录来使用它。如何使用OAuth获取Google Analytics数据?

我有一个解决方案,它使用用户的电子邮件和密码进行分析。我正在寻找一种解决方案,不需要用户的电子邮件和密码,但找不到任何东西。

怎么办?任何建议或链接将不胜感激。

感谢

+0

分析也可以分享给特定用户(在电子邮件的基础上) – Adeel 2011-02-15 15:36:10

回答

11

好的,经过几天的斗争,我终于明白了这一点。互联网上没有文件,以前做过这件事的人不想因为某种原因分享他们的成功。我发现这个帮助我的这个discussion

为了使它工作,你需要从DotNetOpenAuthhttp://www.dotnetopenauth.net/gdatahttp://code.google.com/p/google-gdata/

所以

using DotNetOpenAuth.ApplicationBlock; 
using DotNetOpenAuth.OAuth; 

using Google.GData.Client; 
using Google.GData.Analytics; 

在DotNetOpenAuth有一个名为OAuthConsumer样本项目,你需要的。 将其更改为requiest授权分析:

GoogleConsumer.RequestAuthorization(google, GoogleConsumer.Applications.Analytics); 

这将让你令牌和令牌密钥。 您可以使用它们像这样:

 GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cp", TokenManager.ConsumerKey); //ConsumerKey actually is the name of web application 
     requestFactory.ConsumerKey = TokenManager.ConsumerKey; 
     requestFactory.ConsumerSecret = TokenManager.ConsumerSecret; 
     requestFactory.Token = AccessToken; 
     requestFactory.TokenSecret = TokenManager.GetTokenSecret(AccessToken); 
     requestFactory.UseSSL = true; 
     AnalyticsService service = new AnalyticsService(requestFactory.ApplicationName); // acually the same as ConsumerKey 
     service.RequestFactory = requestFactory; 

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

     DataQuery query1 = new DataQuery(dataFeedUrl); 

此服务,你可以像使用herehere

而最后一件事,你将无法使用尝试和测试它localhost所以你需要一个域必须注册谷歌here为了获得消费者的关键和秘密

+0

我下载了所有这些库,并没有像service.RequestFactory = requestFactory;这样的成员。另外,您是否偶然知道如何在名称空间中使用Google Analytics类?Google.Apis.Analytics.v3 – 2012-01-20 13:37:56

1

有对可用于访问谷歌Analytics(分析)数据导出API谷歌的数据验证的.NET/C# class(因为API是谷歌数据标准的一部分,虽然你可能需要做出谷歌分析具体的调整。)*

通过创建Google Registered Application可以更好地管理身份验证,因为这样您可以在没有安全警告的情况下进行身份验证(并且就此而言,安全失误)。

有三种形式的支持认证; '安全'/无密码的是OAuthAuthSub(这是Google专有版本的OAuth);硬编码的用户名和密码版本被Google称为“ClientLogin”,并且不被认为是安全的或者不适用于多用户应用程序。

*(由于您所标记的问题

编辑:在使用AuthSub或OAuth的使用.NET库的更多细节:

AuthSubSupport:http://code.google.com/p/google-gdata/wiki/AuthSubSupport

如何使用

代码示例用于OAuth身份验证的库:http://code.google.com/apis/gdata/docs/auth/oauth.html#2LeggedOAuth(单击.NET选项卡)。

+1

指向http://code.google.com/apis/gdata/client-cs.html的链接不提供任何合理的检查,显示使用ClientLogin使用不可接受的电子邮件和密码。 Google文档根本没有帮助。我不知道如何手动生成所有这些庞大繁琐的请求,然后解析响应。对于没有多少年经验的人来说,这个任务对我来说似乎是绝望的。 – Burjua 2011-02-23 17:42:36

+0

@Burjua看到我的2个编辑。他们应该帮忙。我知道你正在经历什么 - 我必须为PHP做这件事,而且这并不容易。但这些指南很有帮助。 – Yahel 2011-02-23 18:09:52

-1

我不认为你需要搞砸OAuth。

谷歌分析API允许您传递凭据。从这个数据馈送示例开始。

http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/Analytics_DataFeed_Sample/dataFeed.cs

// Configure GA API and do client login Authorization. 
AnalyticsService asv = new AnalyticsService("gaExportAPI_acctSample_v2.0"); 
asv.setUserCredentials(clientUser, clientPass); 

这里下载

​​

客户端库要获取数据的查询的感觉,玩这个,然后将值复制到上面的例子中

http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html 
相关问题