如何使用OAuth获得谷歌Analytics(分析)数据?如何使用、数据、OAuth、Analytics

2023-09-02 10:35:53 作者:撩爆你的少女心

海兰家伙,我们正在开发一个系统,该系统将为用户提供访问谷歌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.

感谢

推荐答案

好了,伙计们,经过奋斗了几天,我终于想通了这一点。有互联网和人民谁之前,已经做了,不想分享的一些原因,他们的成功上没有任何文档。我发现这个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);

此服务,您可以使用像here或here

This service you can use like here or here

和过去的事情,你将无法使用,试图对本地主机测试它,所以你需要必须与谷歌的

 
精彩推荐
图片推荐