如何使用OAuth获得谷歌Analytics(分析)数据? [英] How to get Google Analytics data using OAuth?

查看:304
本文介绍了如何使用OAuth获得谷歌Analytics(分析)数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海兰家伙,我们正在开发一个系统,该系统将为用户提供访问谷歌Analytics(分析)。我想实现它的方式,使用户无需输入自己的谷歌登录凭据上我们的网站,所以试图得到它的工作使用其登录。

Hy guys, we are developing a system which will provide users with access to Google Analytics. I'm trying to implement it in the way so user don't need to enter their Google login credentials on our site, so trying to get it work using their login.

我有一个解决方案,使用用户的电子邮件和密码,得到的分析。我在寻找它不要求用户的电子邮件地址和密码,但找不到任何解决办法。

I have a solution which gets analytics using user's email and password. I'm looking for a solution which will not require user's email and password but can not find anything.

如何能不能做到?任何建议或链接将AP preciated。

How can it be done? any advices or links will be appreciated.

感谢

推荐答案

好了,伙计们,经过奋斗了几天,我终于想通了这一点。有互联网和人民谁之前,已经做了,不想分享的一些原因,他们的成功上没有任何文档。我发现这个<一href="http://groups.google.com/group/gdata-dotnet-client-library/browse_thread/thread/ca59ad5e9f9f0d20?pli=1">discussion这帮助了我。

Ok, guys, after a few days of struggle I finally figured this out. There is no documentation on the Internet and people who had done it before did not want to share their success by some reason. I found this discussion which helped me.

要使它工作,你需要 DotNetOpenAuth HTTP://www.dotnetopenauth。净/ GDATA HTTP: //$c$c.google.com/p/google-gdata/

To make it work you will need DotNetOpenAuth from http://www.dotnetopenauth.net/ and gdata from http://code.google.com/p/google-gdata/

所以

using DotNetOpenAuth.ApplicationBlock;
using DotNetOpenAuth.OAuth;

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

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

In DotNetOpenAuth there is sample project named OAuthConsumer which you need. Change it to requiest authorization for Analytics:

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

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

This will get you Token and Token secret. You can use them like this:

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

此服务,您可以使用像<一个href="http://$c$c.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/Analytics_AccountFeed_Sample/accountFeed.cs">here或<一href="http://$c$c.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/Analytics_DataFeed_Sample/dataFeed.cs">here

This service you can use like here or here

和过去的事情,你将无法使用,试图对本地主机测试它,所以你需要必须与谷歌的here 为了得到消费者的密钥和密码

And the last thing, you WILL NOT be available to try and test it on localhost so you will need a domain which MUST be registered with Google here in order to get consumer key and secret

这篇关于如何使用OAuth获得谷歌Analytics(分析)数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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