Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 谷歌分析API 3-错误:“;无效的“授权”;,说明:“&引用;,Uri:“&引用;_.net_C# 4.0_Google Analytics Api - Fatal编程技术网

.net 谷歌分析API 3-错误:“;无效的“授权”;,说明:“&引用;,Uri:“&引用;

.net 谷歌分析API 3-错误:“;无效的“授权”;,说明:“&引用;,Uri:“&引用;,.net,c#-4.0,google-analytics-api,.net,C# 4.0,Google Analytics Api,今天,我用谷歌搜索了这个问题,没有任何解决办法 我正在尝试使用服务帐户构建一个非常简单的Google Analytics数据请求控制台应用程序。我已在Google开发者控制台中设置了所有必需的详细信息,但我收到以下错误: An unhandled exception of type 'Google.Apis.Auth.OAuth2.Responses.TokenResponseException' occurred in Google.Apis.dll Additional

今天,我用谷歌搜索了这个问题,没有任何解决办法

我正在尝试使用服务帐户构建一个非常简单的Google Analytics数据请求控制台应用程序。我已在Google开发者控制台中设置了所有必需的详细信息,但我收到以下错误:

An unhandled exception of type 'Google.Apis.Auth.OAuth2.Responses.TokenResponseException'          
occurred in Google.Apis.dll

Additional information: Error:"invalid_grant", Description:"", Uri:""
下面是我的控制台应用程序中的代码(隐藏了键):

任何帮助都将不胜感激

请注意,以下是我遵循的一些来源:


如果其他人也有同样的问题,结果证明我的凭据是错误的:

  • 仔细检查您使用的是服务帐户电子邮件结尾“@developer.gserviceaccount.com”
  • 检查下载的
    .p12
    文件是否位于调试文件夹中,并提供正确的私钥密码(创建服务帐户时提供给您)

  • 这和Google Maps Javascript API v3有什么关系?我甚至没有意识到它被标记了!干杯,我将删除它。除了下面的答案,请确保系统时钟设置为正确的时间。看,我也有同样的问题。已经检查了谷歌提供的服务帐户电子邮件、.P12证书和标准密码“nodatasecret”。当我尝试使用IList calendarList=service.calendarList.List().Execute().items获取日历项时我仍然收到错误:错误:“无效的授权”,描述:,Uri:。知道吗?也许这个答案会有帮助:是的,我也有同样的问题。
    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();
    
        }
    
    }
    }