未找到 OAuth 客户端 - Google Apps 脚本 - BigQuery [英] The OAuth Client was not found - Google Apps Script - BigQuery

查看:33
本文介绍了未找到 OAuth 客户端 - Google Apps 脚本 - BigQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用应用脚本将 BigQuery 结果加载到 Google 电子表格中.这是我的代码

I am trying to use App Script to load BigQuery results into a Google Spreadsheet. Here is my Code

function runQuery() {
var projectId = 'xxxxx';

var request = {
  query: 'select * from ASRLogs.LocationBasedClicks;'
};

var queryResults = BigQuery.Jobs.query(request,projectId);
var jobId = queryResults.jobReference.jobId;

// Check on status of the Query Job. 
var sleepTimeMs = 500;

while(!queryResults.jobComplete)
{
   Utilities.sleep(sleepTimeMs);
   sleepTimeMs *=2;
   queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId);
}

// Get all the rows of the result. 
var rows = queryResults.rows;
while (queryResults.pageToken) {
   queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId, {
       pageToken: queryResults.pageToken
   });
   rows = rows.concat(queryResults.rows);
}

if (rows) {
     var spreadsheet = SpreadsheetApp.create("BigQuery Results");
     var sheet = spreadsheet.getActiveSheet();

     // Append the headers
     var headers = queryResults.schema.fields.map(function(field) {
       return field.name;
     });
     sheet.appendRow(headers)

     // Append the results. 
     var data = new Array(rows.length);
     for (var i = 0; i < rows.length; i ++){
       var cols = rows[i].f;
       data[i] = new Array(cols.length);
       for (var j =0; j < cols.length; j++){
         data[i][j] = cols[j].v;
       }
     }
     sheet.getRange(2,1,rows.length,headers.length).setValue(data);

     Logger.log('Results spreadsheet created: %s', spreadsheet.getUrl());
} else {
  Logger.log('No rows returned.')
}
}

我得到的错误是

错误:invalid_client
未找到 OAuth 客户端.
请求详细信息
- cookie_policy_enforce=false
- scope=https://www.googleapis.com/auth/bigquery https://www.googleapis.com/auth/spreadsheets
- response_type=code gsession
- redirect_uri=https://script.google.com/oauthcallback
- access_type=离线
- 批准提示=强制
- 状态=ACjPJvHwuS-sspO-j9b5vlH_Ul4VokI3QRANL-gwa7YWxz6-RFelZBuLQ2aiiGldHRgR89sMnvlgpsmSOnlquEY45oTt1IgZHWfoWq5e52Jf6l_PYPWQ52Jf6l_PwCyPwCyPwC- client_id=734978265744@developer.gserviceaccount.com
- hl=en

Error: invalid_client
The OAuth client was not found.
Request Details
- cookie_policy_enforce=false
- scope=https://www.googleapis.com/auth/bigquery https://www.googleapis.com/auth/spreadsheets
- response_type=code gsession
- redirect_uri=https://script.google.com/oauthcallback
- access_type=offline
- approval_prompt=force
- state=ACjPJvHwuS-sspO-j9b5vlH_Ul4VokI3QRANL-gwa7YWxz6-RFelZBuLQ2aiiGldHRgR89sMnvlgpsmSOnlquEY45oTt1IgZHWfoWq5e52Jf6l_G-5yPpPwCf40Dkv_JYR9welQPrQ
- client_id=734978265744@developer.gserviceaccount.com
- hl=en

我错过了什么吗?我做了以下工作.

Am I missing something ? I have done the following.

  1. 在 Google 服务中启用 BigQuery API
  2. 在开发者控制台中为项目启用 BigQuery.

推荐答案

我昨天遇到了完全相同的问题.

I had this exact same issue yesterday.

我已经多次复制文档,这将依次复制其中的所有脚本,并在每个脚本后附加副本".我最终得到的是副本副本副本副本副本".

I had been copying a document several times, which will in turn copy all the scripts inside of it, appending each with "Copy of". What I had ended up with was "Copy of Copy of Copy of Copy of Copy of ".

作为最后的手段,我将 Script 项目重命名为",嘿嘿,一切顺利.

As a last resort, I renamed the Script project to "", and hey presto, it came good.

我的理论是,由于脚本项目名称被用作请求授权的应用程序的名称,因此此处存在一些字符限制.

My theory is that since the Script project name is being used as the name of the application requesting authorisation, there is some character limit going on here.

将项目重命名为较短的名称是否可以解决问题?

Does renaming the project to a shorter name fix the issue?

这篇关于未找到 OAuth 客户端 - Google Apps 脚本 - BigQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆