【问题标题】:Google Apps Scripts: OAuthConfig to Big QueryGoogle Apps 脚本:从 AuthConfig 到 Bigquery
【发布时间】:2014-04-09 18:57:54
【问题描述】:

我正在尝试运行将 JSON 数据加载到 Big Query 中的 Google Apps 脚本,但遇到了问题。

我实际上是在尝试在 Adwords Scripts 中运行它,它与 Google Apps Scripts 相同,只是它们没有可用的高级服务,例如 Big Query Service - 所以我不能使用它。

他们确实有 OAuthConfig 服务,您可以从 AdWords 发送 POST 数据,所以我可以通过这种方式发送数据,但我无法让 OAuthConfig 服务首先进行身份验证。

这是我在 Google 应用脚本中运行的内容:

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

ConsumerKey 和 ConsumerSecret 来自 Cloud Console -> APIs & Auth -> Credentials,我在其中为 Web 应用程序设置了客户端 ID。 ConsumerKey 设置为 Client ID (something.apps.googleusercontent.com),ClientSecret 为 Client Secret。为云控制台项目启用了 Big Query API,并且我验证了我能够从其他来源上传数据。

当我尝试执行以下操作时,我不断收到身份验证错误:

var config = {
  'method':'post',
  'oAuthServiceName':'bigquery',
  'oAuthUseToken' : "always",
  'muteHttpExceptions':true
}

var result = UrlFetchApp.fetch('https://www.googleapis.com/upload/bigquery/v2/projects/'+projectName+'/jobs', config);

“服务身份验证失败:bigquery”

我知道我应该在正文中将数据传递给它,但现在我只是尝试先通过服务进行身份验证。

【问题讨论】:

    标签: google-apps-script oauth-2.0 google-oauth google-bigquery google-ads-api


    【解决方案1】:

    在 Apps 脚本中,oAuthConfig 无法使用使用 OAuth 2.0 的 API 进行身份验证。您将需要构建和使用 OAuth 2.0 Web 应用程序流程,如 in this post 所述。

    【讨论】:

    • 遗憾的是 Scripts 没有 OAuth2.0 配置,只有 OAuth1.0 配置。无论哪种方式,您链接到的答案都没有完全帮助,所以我创建了这个要点,其中包含有助于向前发展的代码:gist.github.com/bduerst/10806668
    猜你喜欢
    • 2014-06-30
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多