如何使用 OAuth 获取 Google Analytics 数据? [英] How to get Google Analytics data using OAuth?

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

问题描述

伙计们,我们正在开发一个系统,该系统将为用户提供对 Google Analytics(分析)的访问权限.我正在尝试以这样的方式实现它,以便用户无需在我们的网站上输入他们的 Google 登录凭据,因此尝试使用他们的登录名使其工作.

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

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

谢谢

解决方案

好吧,伙计们,经过几天的挣扎,我终于弄明白了.互联网上没有任何文档,以前做过的人出于某种原因不想分享他们的成功.我发现这个讨论对我有帮助.>

要使其工作,您需要来自 http://www.dotnetopenauth.net/DotNetOpenAuthgdata 来自 http://code.google.com/p/google-gdata/

所以

使用 DotNetOpenAuth.ApplicationBlock;使用 DotNetOpenAuth.OAuth;使用 Google.GData.Client;使用 Google.GData.Analytics;

在 DotNetOpenAuth 中有您需要的名为 OAuthConsumer 的示例项目.将其更改为要求对 Analytics 进行授权:

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

这将为您提供令牌和令牌秘密.您可以像这样使用它们:

 GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cp", TokenManager.ConsumerKey);//ConsumerKey其实就是web应用的名字requestFactory.ConsumerKey = TokenManager.ConsumerKey;requestFactory.ConsumerSecret = TokenManager.ConsumerSecret;requestFactory.Token = AccessToken;requestFactory.TokenSecret = TokenManager.GetTokenSecret(AccessToken);requestFactory.UseSSL = true;AnalyticsService 服务 = new AnalyticsService(requestFactory.ApplicationName);//实际上与 ConsumerKey 相同service.RequestFactory = requestFactory;const string dataFeedUrl = "https://www.google.com/analytics/feeds/data";DataQuery query1 = new DataQuery(dataFeedUrl);

您可以在此处使用此服务此处

最后一件事,您将无法在 localhost 上尝试和测试它,因此您需要一个必须在 Google 此处 以获取消费者密钥和秘密

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.

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

thanks

解决方案

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.

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

so

using DotNetOpenAuth.ApplicationBlock;
using DotNetOpenAuth.OAuth;

using Google.GData.Client;
using Google.GData.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);

This service you can use like here or 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 获取 Google Analytics 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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