gpt4 book ai didi

c# - 如何使用 OAuth 获取 Google Analytics 数据?

转载 作者:太空狗 更新时间:2023-10-29 17:47:13 26 4
gpt4 key购买 nike

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

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

如何实现?任何建议或链接将不胜感激。

谢谢

最佳答案

好的,伙计们,经过几天的努力,我终于弄明白了。互联网上没有文档,以前做过的人出于某种原因不想分享他们的成功。我找到了这个 discussion这对我有帮助。

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

所以

using DotNetOpenAuth.ApplicationBlock;
using DotNetOpenAuth.OAuth;

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

在 DotNetOpenAuth 中有一个名为 OAuthConsumer 的示例项目,您需要它。将其更改为请求分析授权:

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

这将为您提供 token 和 token secret 。您可以像这样使用它们:

        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

最后一件事,您将无法在 localhost 上尝试和测试它,因此您需要一个必须在 Google 上注册的域 here为了获得消费者 key 和 secret

关于c# - 如何使用 OAuth 获取 Google Analytics 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5005665/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com