• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

谷歌AnalyticsAPI 3 - 错误" invalid_grant",说明"",网址""

用户头像
it1352
帮助1

问题说明

我一派的生活出了这个问题今天零的决心!

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

<打击> 有用的,但过时 < /击>

谷歌的code穿行 - 不是在C#.NET

正确答案

#1

事实证明,我有错误的凭据,如果任何人有同样的问题:

It turns out I had the wrong credentials, if anyone else has the same problem:

  1. 双击您正在使用的服务帐户结尾的电子邮件勾选@ developer.gserviceaccount.com
  2. 检查下载的的.p12 文件位于你的debug文件夹,你提供了正确的私钥密码(提供给您,当您创建您的服务帐户)。
  1. Double check you're using the service account email ending "@developer.gserviceaccount.com"
  2. 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
系列文章
更多 icon
同类精品
更多 icon
继续加载