Not getting Authorization dialog for App Script accessing BigQuery Service

风格不统一 提交于 2020-01-06 06:48:31

问题


I am trying to fix some App Scripts which use the BigQuery "Advanced Service" to install some BigQuery jobs. The first new script I ran popped a BigQuery authorization dialog, and everything worked fine, now running hourly. The second new script ran initially, but is now failing with:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

This began about 12 hours after the initial authorization, so it seems like something expired. But, I can't figure out how to trigger the authorization dialog to appear. Also, I expected an authorization would be required for each distinct function, yet the second one initially ran without asking for BigQuery permissions.

Additional Info: Here is the .gs file I am executing:

function runQuery() {
  var projectId = redacted;

  var configuration = {
    "query": {
      "useQueryCache": false,
      "destinationTable": {
          "projectId": projectId,
          "datasetId": redacted,
          "tableId": redacted
        },
      "writeDisposition": "WRITE_TRUNCATE",
      "createDisposition": "CREATE_IF_NEEDED",
      "allowLargeResults": true,
      "query": redacted
    }
  };
  var job = {
    "configuration": configuration
  };

  var jobResult = BigQuery.Jobs.insert(job, projectId);
  var jobId = jobResult.jobReference.jobId;
  Logger.log(jobResult);
}

The first time I ran a very similar query, I got a dialog prompting me for BigQuery permissions, as documented here: https://developers.google.com/apps-script/guides/services/authorization I subsequently ran this same script successfully (with slightly different query config). But, then, about 12 hours after first run, I started getting the authorization return quoted above. I thought it might refresh with time, but still get same failure.


回答1:


Turns out this has been working all along. The authorization error was being generated by my attempt to look at the job results, not by the job itself. Doh!



来源:https://stackoverflow.com/questions/49478149/not-getting-authorization-dialog-for-app-script-accessing-bigquery-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!