0

Google Developers Console에서 Analytics API를 사용 설정하고 내 자격 증명 (클라이언트 ID 및 클라이언트 비밀번호)을 올바르게 입력했습니다.Google Apps Script에서 웹 로그 분석에 액세스 할 수 없습니다.

var clientId = "(censored)"; 
var consumerSecret = "(censored)"; 

var oAuthConfig = UrlFetchApp.addOAuthService('analytics'); 
oAuthConfig.setAccessTokenUrl("https://accounts.google.com/o/oauth2/token"); 
oAuthConfig.setRequestTokenUrl("https://accounts.google.com/o/oauth2/token?scope=https://www.googleapis.com/auth/analytics.readonly"); 
oAuthConfig.setAuthorizationUrl("https://accounts.google.com/o/oauth2/auth"); 
oAuthConfig.setConsumerKey(clientId); 
oAuthConfig.setConsumerSecret(consumerSecret); 

var url = "https://www.googleapis.com/analytics/v3/data/ga?ids=ga:91669545&start-date=2014-12-01&end-date=2014-12-31&metrics=ga:sessions,ga:bounces"; 
var response = UrlFetchApp.fetch(url,{"muteHttpExceptions":true}); 
Logger.log(response); 

내 "응답"그것도 API에서 인증 정보를 제출하지 않는 의미하는 401 오류를 반환 그렇지 않으면 내 자격 증명이 잘못되었습니다 말을 반환, 다음은 내 Google Apps 스크립트 내 코드입니다. Google Apps Script 애플리케이션에서도 다음 오류 메시지를 표시합니다.

액세스가 구성되지 않았습니다. 프로젝트에 API가 사용 설정되어 있지 않거나 IP 키당 또는 Referer 제한이 API 키에 구성되어 있으며 요청이 이러한 제한 사항과 일치하지 않습니다. Google Developers Console을 사용하여 구성을 업데이트하십시오.

oauth를 사용할 수없는 이유에 대한 아이디어가 있습니까? 감사!

답변

0

UrlFetchApp.setOAuthService()은 사용하려는 것으로 보이는 OAuth2을 지원하지 않습니다.

은 이슈 트래커에 대한 요청 :에 Google 팀 중 하나에서 답을 심판 Update #9 to issue #929

1 개 또는 2 애플리케이션 스크립트에서 OAuth2를 연결을 만들 수있는 방법,하지만이 방법이 있습니다.

는이 질문에 대해 참조하는 방법은 연결 : https://github.com/googlesamples/apps-script-oauth2 또는 http://ramblings.mcpher.com/Home/excelquirks/oauthtoo/ezyoauth2


내장 웹 로그 분석 API 방법을 애플리케이션 스크립트를 사용해보십시오 - 이것은 당신이 웹 로그 분석 통합을 위해 필요한 커버 할 수있다 : https://developers.google.com/apps-script/advanced/analytics

관련 문제