【发布时间】:2015-01-11 02:49:40
【问题描述】:
我已在 Google Developers Console 中打开了我的 Analytics API,并且我的凭据(客户端 ID 和客户端密码)输入正确。这是我的 Google Apps 脚本中的代码:
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);
我的“响应”返回 401 错误,这意味着它甚至没有在 API 上提交授权信息,否则它会返回说我的凭据不正确。 Google Apps 脚本应用程序也向我抛出此错误:
访问未配置。您的项目未启用 API,或者您的 API 密钥上配置了 per-IP 或 per-Referer 限制,并且请求与这些限制不匹配。请使用 Google Developers Console 更新您的配置。
关于为什么我不能让 oauth 在这里工作有什么想法吗?谢谢!
【问题讨论】:
标签: google-apps-script google-analytics oauth-2.0 google-oauth