Permissions failure with Execution API from Androi

2019-02-28 21:02发布

I am able to successfully get the Execution API Quickstart to work for accessing filenames.

But augmenting the Quickstart script to use Spreadsheet functions triggers an error of type "No authentication challenges found".

The addition of DriveApp.getFilesByName() does not cause any permissions problems, it is the addition of SpreadsheetApp.create() that triggers the error. Saving the augmented script generates a message that the script requires additional permissions. I have tried:

  • creating/saving a new/complete script so all required permissions are established with the first script instantion
  • deleting the app data on the target to force new permissions to be granted
  • deleting the app on the target to force new permissions to be granted
  • regenerating a new SHA1 key and re-credential-ing with the new key to re-initiate the permission granting process

My code:

function getFoldersUnderRoot() {
  var my_ss = "SDRP-Log-Test";
  var my_sheet = "month";
  var files = DriveApp.getFilesByName(my_ss);
  var file = !files.hasNext() ? SpreadsheetApp.create(my_ss) : files.next();
  var ss = SpreadsheetApp.openById(file.getId());

  var root = DriveApp.getRootFolder();
  var folders = root.getFolders();
  var folderSet = {};
  while (folders.hasNext()) {
    var folder = folders.next();
    folderSet[folder.getId()] = folder.getName();
  }
  return folderSet;
}

I have independently verified that the Spreadsheet scripting works correctly via the development interface, so the scripting works.

build.gradle:

defaultConfig {
    applicationId "com.jackb.sdrp"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

Development platform:

  • Host: Win10 & Android Studio 1.4 (Current patching)

Target:

  • Samsung Galaxy S2 & Android 4.1.2
  • Samsung Galaxy S5 & Android 5.1.1

1条回答
迷人小祖宗
2楼-- · 2019-02-28 21:06

By adding SpreadsheetApp calls, you've modified the authentication scope required for your script. You need to update your scope to include Spreadsheets.

To use the API, you must supply a valid OAuth token that covers all the scopes used by the script (not just the ones used by the called function). To find the correct scopes to include in the authentication token, open the project in the script editor, then select File > Project properties and click the Scopes tab.ref

查看更多
登录 后发表回答