谷歌AnalyticsAPI 3 - 错误" invalid_grant",说明"",网址""
问题说明
我一派的生活出了这个问题今天零的决心!
I've '谷歌d' the life out of this issue today with zero resolve!
我想建立使用服务帐户很简单的谷歌Analytics(分析)数据请求控制台应用程序。我已经建立了在谷歌开发者控制台所有需要的细节,但我收到以下错误:
I am trying to build a very simple Google Analytics data request console app using a Service account. I have set up all the required details in the Google Developers Console but I am getting the following error:
An unhandled exception of type 'Google.Apis.Auth.OAuth2.Responses.TokenResponseException'
occurred in Google.Apis.dll
Additional information: Error:"invalid_grant", Description:"", Uri:""
下面是我的控制台应用程序的code(连键隐藏):
Below is the code in my console app (with keys hidden):
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Analytics;
using Google.Apis.Analytics.v3;
using Google.Apis.Analytics.v3.Data;
using System;
namespace GoogleAnalyticsAPI
{
public class Program
{
public static void Main(string[] args)
{
string profileId = "12345678";
string serviceAccountEmail = "123456789abcdefghijklmnopq@developer.gserviceaccount.com";
X509Certificate2 certificate = new X509Certificate2(@"PrivateKey.p12", "mypassword", X509KeyStorageFlags.Exportable);
// Create credentials
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { AnalyticsService.Scope.Analytics }
}.FromCertificate(certificate));
// Create the service
var service = new AnalyticsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Google Analytics API"
});
string startDate = "2014-07-01";
string endDate = "2010-07-31";
DataResource.GaResource.GetRequest request = service.Data.Ga.Get(string.Format("ga:{0}", profileId), startDate, endDate, "ga:visits, ga:newVisits");
request.Dimensions = "ga:city";
GaData data = request.Execute();
}
}
}
在这里任何帮助将是很大的AP preciated!
Any help here would be greatly appreciated!
请注意,这里有一些资源,我跟着:
Note, here are some sources I've followed:
<一个href="http://www.toplinestrategies.com/dotneters/net/accessing-and-querying-谷歌-analytics-via-service-account-c/"相对=nofollow>教程随后获得上述code
<打击> 有用的,但过时 < /击>
正确答案
事实证明,我有错误的凭据,如果任何人有同样的问题:
It turns out I had the wrong credentials, if anyone else has the same problem:
- 双击您正在使用的服务帐户结尾的电子邮件勾选@ developer.gserviceaccount.com
- 检查下载的
的.p12
文件位于你的debug文件夹,你提供了正确的私钥密码(提供给您,当您创建您的服务帐户)。
- Double check you're using the service account email ending "@developer.gserviceaccount.com"
- Check the downloaded
.p12
file is located in your debug folder and you supply the correct private key password (given to you when you create your service account).
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfgikh
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22