こんにちは、サービス アカウントを使用して ASP.NET/C# で Google アナリティクス API Ver 3 を使用しようとしていますが、うまく動作しません。すべてがコンパイルされますが、GaData d = r.Execute(); を呼び出すとき。GoogleApiException 「「ids」のパラメーター検証に失敗しました。これを引き起こす可能性のある情報/ヘルプは大歓迎です。
//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.完全なスタック トレース
c:\code.google.com\google-api-dotnet-client\default\Tools\ の Google.Apis.Http.HttpClientFactory.CreateHttpClient(CreateHttpClientArgs args) で Google.Apis.Http.HttpClientFactory.CreateHandler(CreateHttpClientArgs args) でBuildRelease\bin\Release\release140\default\Src\GoogleApis\Apis\Http\HttpClientFactory.cs: c:\code.google.com\google- の Google.Apis.Services.BaseClientService.CreateHttpClient(Initializer initializer) の 36 行目api-dotnet-client\default\Tools\BuildRelease\bin\Release\release140\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:Google.Apis.Services.BaseClientService..ctor(Initializer initializer) の 220 行目c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Release\release140\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:Google.Apis の 182 行目。 Analytics.v3.d:\GoogleAnalyticDotNet\GoogleAnalyticDotNet\GoogleAnalyticDotNet\Program.cs:line 58 の GoogleAnalyticDotNet.Program.Main(String[] args) の AnalyticsService..ctor(Initializer initializer): System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args ) で System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String[] args) で Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() で System.Threading.ThreadHelper.ThreadStart_Context(オブジェクト状態) で System.Threading.ExecutionContext. System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback コールバック、オブジェクト状態、Boolean preserveSyncCtx) での RunInternal(ExecutionContext executionContext、ContextCallback コールバック、オブジェクト状態、ブール値 preserveSyncCtx)。System.Threading.ThreadHelper.ThreadStart() で実行 (ExecutionContext 実行コンテキスト、ContextCallback コールバック、オブジェクト状態)