简体   繁体   English

如何使用 Google Apps Script Execution API + Java 创建 Google 表单?

[英]How to create a Google Form using Google Apps Script Execution API + Java?

I tried a simple Java command-line application that makes requests to the Google Apps Script Execution API.我尝试了一个简单的 Java 命令行应用程序,它向 Google Apps Script Execution API 发出请求。 Something like this: https://developers.google.com/apps-script/guides/rest/quickstart/java#prerequisites .像这样: https : //developers.google.com/apps-script/guides/rest/quickstart/java#prerequisites But it doesn't work.但它不起作用。

Google Apps Script Editor: Google Apps 脚本编辑器:

function createForm() {

  var form = FormApp.create('New Form');

}

Java Error: Java错误:

Credentials saved to /home/palmaslab/.credentials/script-java-quickstart.json
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
        at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
        at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
        at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
        at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
        at org.gradle.AppsScriptApiQuickstart.main(AppsScriptApiQuickstart.java:188)

API returning an HTTP 401 response when calling the API. API 在调用 API 时返回HTTP 401响应。 These error could indicate any of:这些错误可能表明:

Token expiry, token revocation, token not authorized for needed scope, request not authorized correctly with OAuth 2.0 protocol .令牌到期、令牌撤销、令牌未授权用于所需范围、请求未使用OAuth 2.0 协议正确授权。 You may also check Forms Service for more information regarding forms services您还可以查看Forms Service以获取有关Forms Service的更多信息

Here's a related issue of 401: Unauthorized: Google apps script and execution API: latest version of script throws error这是 401 的相关问题:未经授权: Google 应用程序脚本和执行 API:最新版本的脚本引发错误

Seems you have to authorize previously the scopes.似乎您必须事先授权范围。 Maybe it could help you: Manual authorization scopes for Sheets, Docs, and Forms也许它可以帮助您: 表格、文档和表单的手动授权范围

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Google Apps脚本或Java在Google+社区上发布 - How to Post on Google+ community using Google Apps Script or Java Google API Apps脚本函数执行始终出现500错误 - Google API Apps Script Function Execution Consistently Gets 500 Error 如何使用 Java API 在谷歌云存储桶中创建一个空文件夹 - How to create an empty folder in google cloud bucket using Java API 如何使用Java和Drive API在Google Drive上创建电子表格 - How to create a Spread Sheet on Google Drive Using Java and Drive API 如何从Java应用程序外部运行Google Apps脚本 - How to run google apps script externally from java application 如何使用Google API服务库(Java)运行Google App脚本 - How to run a Google App Script using Google API Service Library (Java) 使用Google Spreadsheet API在Google中的Google驱动器中创建电子表格 - Create Spreadsheet using Google Spreadsheet API in Google drive in Java 使用 google docs api (java) 创建 Google 文档 - Create Google docs using google docs api (java) 与在Eclipse中使用常规Java代码相比,使用Google Apps脚本与Google表格进行交互有什么优势? - What are advantages of using Google Apps Script to interact with Google Sheets over using regular Java code in Eclipse? Google Apps管理Java API中的批处理操作 - Batching operations in Google Apps Admin Java API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM