OAuth 2를 사용하여 최신 버전의 보고서 API를 사용하려고합니다. 아직이 버전을 사용하는 사용자가 많지는 않은 것으로 나타났습니다. 예제를 찾기가 정말 어렵습니다.OAuth 2를 사용하여 Google 웹 로그 분석 보고서 API를 쿼리 할 수 없습니다.
액세스 토큰을 생성하는 데 사용하는 새로 고침 토큰이 있습니다.
private AnalyticsService getAnalyticsService()
{
AuthorizationServerDescription description = new AuthorizationServerDescription();
description.TokenEndpoint = new Uri(login.TokenEndpoint);
description.AuthorizationEndpoint = new Uri(login.AuthorizationEndpoint);
WebServerClient client = new WebServerClient(description, login.ClientId, login.ClientSecret);
OAuth2Authenticator<WebServerClient> authenticator = new OAuth2Authenticator<WebServerClient>(client, authenticate);
AnalyticsService service = new AnalyticsService(authenticator);
return service;
}
private IAuthorizationState authenticate(WebServerClient client)
{
string[] scopes = new string[] { login.ScopeUrl }; // not sure if this is necessary
IAuthorizationState state = new AuthorizationState(scopes) { RefreshToken = login.RefreshToken };
client.RefreshToken(state);
return state;
}
이 잘 작동하는 것으로 나타납니다
{
"access_token" : "ya29.AHES6ZQy67SSLHWJWGWcLbLn69yKfq59y6dTHDf4ZoH9vHY",
"token_type" : "Bearer",
"expires_in" : 3600
}
을하지만, 내가 요청을 수행 할 때, 나는 오류를 얻고있다.
AnalyticsService service = getAnalyticsService();
ManagementResource.ProfilesResource.ListRequest request = service.Management.Profiles.List("~all", "~all");
return request.Fetch();
이것은 내가 오류는 다음과 같습니다 : 예를 들어, 다음 는 오류가 발생하는 쿼리입니다
내가 유효한 프로필 ID를 제공하는 다른 쿼리를 시도{"error":{"errors":[{"domain":"global","reason":"authError","message":"Invalid
Credentials","locationType":"header","location":"Authorization"}],"code":401,"message":"Invalid
Credentials"}}
. 그러나 나는 입니다. 항상 401 오류가 발생하며, 권한이 없다고 말합니다. 사람들이이 코드를 사용하는 예제를 찾는 데 문제가 있습니다. 뭔가 간단한 URL 같은 것이 될 수 있습니다. 불행히도, 나는 말하기에 방법이 없습니다. 액세스 토큰을 얻을 수있는 것이 이상하게 보입니다. 그러나 나는 어떤 쿼리도 수행 할 수 없습니다.
https://www.google.com/analytics/feeds/
에 : 당신이 적절한 범위없이 액세스를 얻으려고 노력했기 때문에
https://www.googleapis.com/auth/analytics.readonly
당신은 인증 오류가 발생하는 OAuth를 2로