안녕하세요 저는 서비스 계정을 사용하여 ASP.NET/C#에서 Google 애널리틱스 API 버전 3을 사용하려고합니다. 작동하지 않는 것 같습니다. 모든 것이 컴파일되지만 GaData를 호출 할 때 d = r.Execute(); 내가 식별자 ""매개 변수 유효성 검사에 실패했습니다 "는 GoogleApiException를 얻을. 아마도이 발생할 수 있습니다 무엇에 대한 어떤 정보/도움이 많이 주시면 감사하겠습니다.Google 애널리틱스 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 : 줄 36 at Google.Apis.Services.BaseClientService.CreateHttpClient (초기화 프로그램 초기화 프로그램) (c : \ code.google.com \ google-api-dotnet-client \ default \ Tools \ BuildRelease \ bin \ Release \ release140 \ default \ Src \ GoogleApis) \ Apis \ Services \ BaseClientService.cs : line 220 Google.Apis.Services.BaseClientService..ctor (초기화 프로그램 초기화 프로그램) (c : \ code.google.com \ google-api-dotnet-client \ default \ Tools \ BuildRelease) \ bin \ Release \ release140 \ default \ Src \ GoogleApis \ Apis \ Services \ BaseClientService.cs : 행 182 Google.Apis.Analytics.v3.AnalyticsService..ctor (초기화 프로그램 초기화 프로그램) GoogleAnalyticDotNet.Program.Main (String [] args) d : \ GoogleAnalyticDotNet \ GoogleAnalyticDotNet \ GoogleAnalyticDotNet \ Program.cs : 줄 58 at System.AppDomain._nExecuteAssembly (RuntimeAssembly assembly, String [] args) at System.AppDomain.ExecuteAssembly (String assemblyFi 제작, 증거 assemblySecurity 문자열 [] 인수) System.Threading.ExecutionContext.RunInternal에서 System.Threading.ThreadHelper.ThreadStart_Context (객체 상태)에서 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()에서 (ExecutionContext에 ExecutionContext에, ContextCallback 콜백 System.Threading.ExecutionContext.Run (ExecutionContext에 ExecutionContext에, ContextCallback 콜백에서 객체 상태 부울 preserveSyncCtx) , 상태 객체 System.Threading.ExecutionContext.Run (ExecutionContext에 ExecutionContext에, ContextCallback 콜백에서) 를 부울 preserveSyncCtx를 상태 객체) 에서 System.Threading.ThreadHelper.ThreadStart()
1. 전체 스택 추적을 추가 할 수 있습니까? 그걸 탐구하는 것이 훨씬 쉬울 것입니다. 2. 다른 전화가 도움이 되었습니까? 나는 그 서비스 요청이 실패하는 것만 알아 내고 싶다 ... – peleyal
안녕 peleyal, 1. 나는 포스트를 편집하고 스택 추적을 추가했다. 2. 아니, 나는 일할 것을 요구하지 않았다. – user1697748