.net - 如何将 Google Analytics API 与 2-legged OAuth(Google Apps for business)一起使用?

标签 .net oauth google-analytics google-api 2-legged

我想为我工作的业务开发应用程序。我们正在使用 Google Apps 并希望从 Google Analytics 获取数据并将其显示在我们的一个网络应用程序中。我不希望客户看到任何授权应用程序的请求。我想像这样使用 2-legged OAuth http://www.google.com/support/a/bin/answer.py?hl=en&answer=162105但 Google Analytics 不在列表中。我还能使用它吗?是否支持 .NET Google Data API libraryGoogle API .NET Client ?

编辑 1 :

使用 Google API .NET Client ,我想出了一些符合我的感觉的东西:

var auth = new Google.Apis.Authentication.OAuth2LeggedAuthenticator(DOMAIN_CONSUMER_KEY, DOMAIN_CONSUMER_SECRET, USER_TO_IMPERSONATE, DOMAIN);

var service = new Google.Apis.Analytics.v3.AnalyticsService(auth);

service.Key = DEV_KEY_FROM_API_CONSOLE;

var _request = service.Management.Accounts.List();

foreach (var item in _request.Fetch().Items)
{
    Console.WriteLine(item.Name);
}

...但我收到此错误:
Google.Apis.Requests.RequestError 
InvalidCredentials [401]
Errors [
    Message[Invalid Credentials] 
    Location[Authorization - header] 
    Reason[authError] 
    Domain[global]
    ]

谢谢

最佳答案

这篇博文逐步解释了如何使用 Google API .Net 客户端实现 2 条腿身份验证。

http://bittwiddlers.org/?p=212#awp::?p=212

但是,作者通过以下评论结束了他的帖子:

The above information specific to the google-api-dotnet-client project is relevant, but that library leaks memory like a sieve and will kill your performance if you try to do any asynchronous work or use 2LO (on behalf of multiple users).



祝你好运,如果你找到更好的解决方案,请告诉我,我对这个问题有点厌烦......

关于.net - 如何将 Google Analytics API 与 2-legged OAuth(Google Apps for business)一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7534480/

相关文章:

OAuth2 : Update refresh token along with the access token or not?

c# - 访问 token Google+

php - 使用 OAuth 2.0 访问 Google API(特别是 Blogger)(PHP)

google-analytics - 子域作为过滤器(Google Analytics API)

c# - WM 和 C# : How to set up a WiFi Ad-Hoc connection programmatically?

.net - 框架设计——为什么.net没有实现混淆,却提供ObfuscateAssemblyAttribute?

c# - 在项目中看不到 JSON 文件

c# - 从 WCF 服务打印 HTML 到网络上的特定打印机

javascript - 全局函数在函数内部不可见

javascript - 如何在 Google Analytics(gtag.js、analytics.js)过滤器中设置用户定义字段?