[英]How do I Modify my Workspace Listing in Google Cloud Platform
[英]How do I connect a script application to the Google Cloud Platform?
如何將腳本應用程序連接到 Google Cloud Platform? 我找到了如何手動完成。 但是如何以編程方式進行呢?
File file3 = new File()
.setName("appsscript")
.setType("JSON")
.setSource("{\n"
+ " \"timeZone\": \""+TimeZone.getDefault().toZoneId().toString()+"\",\n"
+ " \"dependencies\": {},\n"
+ " \"exceptionLogging\": \"STACKDRIVER\",\n"
+ " \"executionApi\": {\n"
+ " \"access\": \"ANYONE\"\n"
+ " } }");
Content content = new Content().setFiles(Arrays.asList(file1, file2, file3));
script.projects().updateContent(project.getScriptId(), content).execute();
Version version = new Version();
version.setVersionNumber(1);
Version versions = script.projects().versions().create(project.getScriptId(), version).execute();
DeploymentConfig deploymentConfig = new DeploymentConfig();
deploymentConfig.setManifestFileName("appsscript");
deploymentConfig.setVersionNumber(versions.getVersionNumber());
Deployment deployment = script.projects().deployments().create(project.getScriptId(), deploymentConfig).execute();
Operation op = script.scripts().run(deployment.getDeploymentConfig().getScriptId(), request).execute();
執行此代碼時,我得到:
POST https://script.googleapis.com/v1/scripts/xxxx:run
{
"code": 403,
"errors": [
{
"domain": "global",
"message": "The caller does not have permission",
"reason": "forbidden"
}
],
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
我不明白你想做什么。
推論:在 Google Cloud Platform 上運行 Apps 腳本的最簡單方法是使用 Apps Script Console 。 按照慣例 (!),開發人員使用 Apps腳本控制台來創建|編輯、部署、測試 Apps 腳本。 如果不知道更多,我想你會想走這條路,除非你不能。
但是 (!) 與所有 Google 的服務 (API) 一樣,使用 (n API) 客戶端庫(例如 Apps Script)直接與服務交互是完全合理的。 這就是您正在做的事情,我認為(!?),您正在使用Google API Client Library for C#|.NET for Apps Script來執行此操作。 這很酷。
當您使用客戶端庫時,您必須對其請求進行身份驗證。 請參閱此處的 .NET 入門指南,了解有關創建 Google 項目、在項目中啟用服務(例如 Apps 腳本)以及創建可用於驗證服務的憑據的更多信息。
如果您的 Apps 腳本將訪問用戶數據,那么您將需要使用 Web|Installed 應用程序流向用戶提供 (Google) 登錄提示、范圍等,並讓他們批准您的腳本訪問他們的數據。
如果您的 Apps 腳本不會訪問用戶數據,那么您可能會改用服務帳戶。 有一種非常簡單的機制可以使用稱為Application Default Credentials (ADC)的服務帳戶憑據進行身份驗證。 如果您使用服務帳戶,則應使用 ADC。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.