2013-07-16 71 views
0

您好,我嘗試使用ASP.NET/C#中的Google Analytics API Ver 3,並使用服務帳戶,似乎無法使其工作。一切都編譯完成,但調用GaData時d = r.Execute(); 我得到一個GoogleApiException「參數驗證失敗‘IDS’。上什麼可能導致此任何信息/幫助將非常感激。Google Analytics Repoting API .NET -

 //This is the API url which we're storing to a string 
     string scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue(); 

     //For whatever reason, this is labelled wrong. It is the email address 
     //that you have added as a user to your Analytics account 
     string clientId = "***********@developer.gserviceaccount.com"; 

     //This is the physical path to the key file file. 
     string keyFile = @"C:\key\***********.p12"; 

     //The password Google gives you. 
     string keyPassword = "notasecret"; 

     //Store the authentication description 
     AuthorizationServerDescription desc = GoogleAuthenticationServer.Description; 

     //Create a certificate object to use when authenticating 
     X509Certificate2 key = new X509Certificate2(keyFile, keyPassword, X509KeyStorageFlags.Exportable); 

     //Now, we will log in and authenticate, passing in the description 
     //and key from above, then setting the accountId and scope 
     AssertionFlowClient client = new AssertionFlowClient(desc, key) 
     { 
      ServiceAccountId = clientId, 
      Scope = scope 
     }; 

     //Finally, complete the authentication process 
     //NOTE: This is the first change from the update above 
     OAuth2Authenticator<AssertionFlowClient> auth = 
      new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState); 

     //First, create a new service object 
     AnalyticsService gas = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = auth }); 

     //Create our query 
     //The Data.Ga.Get needs the parameters: 
     //Analytics account id, starting with ga: 
     //Start date in format YYYY-MM-DD 
     //End date in format YYYY-MM-DD 
     //A string specifying the metrics 
     DataResource.GaResource.GetRequest r = 
      gas.Data.Ga.Get("ga:nnnnnnnn", "2013-01-01", "2013-01-31", "ga:visitors"); 

     //Specify some addition query parameters 
     r.Dimensions = "ga:pagePath"; 
     r.Sort = "-ga:visitors"; 
     r.MaxResults = 5; 

     //Execute and fetch the results of our query 
     GaData d = r.Execute(); 

1.全堆棧跟蹤

在谷歌.Apis.Http.HttpClientFactory.CreateHandler(CreateHttpClientArgs args) at Google.Apis.Http.HttpClientFactory.CreateHttpClient(CreateHttpClientArgs args)in c:\ code.google.com \ google-api-dotnet-client \ default \ Tools \ BuildRelease \ bin \ Release \ release140 \ default \ Src \ GoogleApis \ Apis \ Http \ HttpClientFactory.cs:line 36 at c. \ code.google.com \ google-api-dotnet-client \ default \ Tools \ BuildRelease \ bin \ Release \ release140 \ default \ Src \ GoogleApis中的Google.Apis.Services.BaseClientService.CreateHttpClient(初始化程序初始化程序) \ Apis \ Services \ BaseClientService.cs:line 220 at Google.Apis.Services.BaseClientService..ctor(Initializer initializer)in c:\ code.google.com \ google-api-dotnet-client \ default \ Tools \ BuildRelease \ bin \ Release \ release140 \ default \ Src \ GoogleApis \ Apis \ Services \ BaseClientService.cs:line 182 at Google.Apis.Analytics.v3.AnalyticsService..ctor(初始化程序初始值設定項) at GoogleAnalyticDotNet.Program.Main(String []參數)在d:\ GoogleAnalyticDotNet \ GoogleAnalyticDotNet \ GoogleAnalyticDotNet \ Program.cs中:line 58 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args) at System.AppDomain.ExecuteAssembly(String assemblyFi樂,證據assemblySecurity,字串[] args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ThreadHelper.ThreadStart_Context(對象狀態) 在System.Threading.ExecutionContext.RunInternal(的ExecutionContext的ExecutionContext,ContextCallback回調,對象狀態,Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state) 在System.Threading.ThreadHelper.ThreadStart()

+0

1.您可以添加完整的堆棧跟蹤嗎?探索那個將會容易得多。 2.其他電話是否適合您?我想弄清楚是否只有那個服務請求失敗... – peleyal

+0

嗨peleyal,1.我編輯帖子,並添加到堆棧跟蹤。不,我沒有接到任何電話工作。 – user1697748

回答

1

我完成了從sam中取出並離開nnnnnnnn ple代碼... derp derp。用配置文件ID替換nnnnnn .. -.-

DataResource.GaResource.GetRequest r = gas.Data.Ga.Get(「ga:nnnnnnnn」,「2013-01-01」,「2013-01- 31「,」ga:visitors「);

感謝peleyal爲你提供幫助。