- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试为我正在设置的 Python 微服务设置一个具有服务器到服务器身份验证的 Google 应用程序脚本 API 可执行文件。
使用快速入门,我能够通过 Auth2 使其工作,但我无法使其与服务帐户一起工作。我将脚本和电子表格的访问权限授予了服务帐户电子邮件。客户端 secret JSON 中的项目 ID 与应用脚本的项目 ID 匹配。我将它部署为一个 API 可执行文件。
下面是我的代码(虽然我不认为代码是问题所在):
from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
from googleapiclient.discovery import build
scopes = [
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/script.external_request',
'https://www.googleapis.com/auth/script.storage',
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/userinfo.email'
]
credentials = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scopes)
http_auth = credentials.authorize(Http())
service = build('script', 'v1', http=http_auth)
request = {'function': 'testApi'}
response = service.scripts().run(body=request, scriptId='SCRIPT_ID').execute()
print(response)
我的应用脚本中的 testApi 函数是一个返回“有效”的简单函数。
我一直收到用户在使用个人帐户时没有权限 (403),在使用组织(G Suite 帐户)时甚至没有 500。
如前所述,Google 文档中的快速入门教程有效,但这没有使用服务帐户。
有没有人使 Google Apps Scripts API 可执行并与服务器到服务器身份验证帐户流一起工作?
最佳答案
您可能想查看有关 Using Google Service Accounts with Google Apps Script 的教程。此示例代码展示了如何使用 Service Accounts 在 Google Apps 脚本中使用 OAuth。
要使此代码正常工作,您需要将 create a Google Service account 与 domain-wide delegation 进行比较,将私钥和客户端电子邮件替换为实际值,并将客户端 ID 添加到具有 Drive API Scope 的 Google Apps 管理控制台。 OAuth 2.0 访问 token 存储在脚本属性中。
var JSON = {
"private_key": "Your Private Key",
"client_email": "serviceacount@project-ctrlq.iam.gserviceaccount.com",
"client_id": "1234567890",
"user_email": "amit@labnol.org"
};
function getOAuthService(user) {
return OAuth2.createService("Service Account")
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
.setPrivateKey(JSON.private_key)
.setIssuer(JSON.client_email)
.setSubject(JSON.user_email)
.setPropertyStore(PropertiesService.getScriptProperties())
.setParam('access_type', 'offline')
.setScope('https://www.googleapis.com/auth/drive');
}
function getUserFiles() {
var service = getOAuthService();
service.reset();
if (service.hasAccess()) {
var url = 'https://www.googleapis.com/drive/v2/files?pageSize=1';
var response = UrlFetchApp.fetch(url, {
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
}
});
Logger.log(response.getContentText());
}
}
function reset() {
var service = getOAuthService();
service.reset();
}
此外,如果您收到 403 Insufficient permission 错误,可能是因为应用程序请求访问未在 Google Apps 管理控制台中授权的 API 范围。 invalid_grant
错误可能是由于托管应用程序的服务器的日期和时间设置不正确所致。
关于python - 使用 Google Apps 脚本 API 可执行文件的服务器到服务器身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46773093/
所以问题是:如何使用标准 C 库以跨平台方式实现简单的自检可执行文件? 在这里,我正在寻找技术,而不是特定的检查方法(如 CRC 或哈希码),但该技术可能包含更适合某些方法的元素(例如见下文)。 目的
我想构建一个 C++ 可执行文件,以便所有库也附加到可执行文件。构建这样一个可执行文件的方法是什么?因此,每当我在其他 PC(运行 Ubuntu)上使用 g++ 编译我的代码时,它不需要运行该可执行文
我在 Netbeans IDE 8.0.1 中编写了一个名为 SampleChat 的 Java GUI 程序,并使用“clean and build”功能创建了一个 jar 文件。 我进入 Netb
我有两个 DLL,一个用 native C++ 编写,另一个用 C++/CLI 编写。前者被注入(inject)到进程中,并在稍后的时间点加载后者。在调试时,我注意到 native DLL 的断点运行
如何访问可执行文件的机器代码(二进制文件)? 详情 我使用的是 Ubuntu (Linux) 我想访问 .exe 文件(文件遵循 PE 格式)的机器代码(二进制文件) 我正在使用 C 来实现 最佳答案
这个问题在这里已经有了答案: Run java jar file on a server as background process (4 个回答) 关闭1年前. 我正在使用命令提示符运行一个可执行
我的 jar 没有运行,我可以告诉它尝试运行,因为 log4j 文件设法创建日志文件夹,但没有任何 react 并且日志为空白。 我的问题是我在名为 bin 的文件夹中有 jar 文件,在名为 lib
我正在为我教育第一学期的编程考试创建一个程序。它应该向用户显示哥本哈根和其他 6 个城市(在其他时区)的时间。用户还应该能够将城市添加到列表中。我正在用 JAVA 编写程序(下面提供源代码)。当我从
我正在查看雅虎的 YUI 压缩器可执行 jar,他们有这个类,从 list 文件链接为“主类”: package com.yahoo.platform.yui.compressor; import j
问题是:从 Eclipse 导出时可执行 jar 中包含什么?我问这个问题是因为我想知道,例如,如果我在项目根目录中有一个图像,该图像是否会包含在导出中? 澄清:我说的是可运行的 jar 文件(已编辑
我知道这个问题已经被问了很多,并且我已经尝试了 eclipse(Kepler、Ganymede、Galileo)、fatJar、netbeans、blueJ、命令行和手册中的大约 20-30 种不同的
我从 IntelliJ 14.03 中的一个工件构建了一个 .jar。当我尝试在 JRE 中打开它时,没有任何反应。这只是一个简单的 GUI。 提前致谢。 最佳答案 在jar位置运行命令,例如 jav
我使用 eclipse 创建了一个可执行 JAR 文件。我在项目文件夹中有资源当框架打开时不会出现。我的意思是当我双击 JAR 文件时。更多的所以,在我尝试删除 JAR 文件后,我收到一条警告,表明该
我创建了一个尺寸相当大(125,000 kb)的可运行 Jar 文件。当我运行它时,该 jar 文件内的应用程序不会显示,但在任务管理器中 javaw.exe(应链接到该 jar 文件)进程正在运行。
我已经使用 Eclipse(文件->导出)为我的 java 程序创建了一个可执行 jar 文件。 当我双击 jar 时,它工作正常。将 jar 文件复制到另一台计算机(Windows)后,我收到错误“
我用 eclipse indigo 创建了一个可执行的 jar 文件,但是当我双击它时什么也没有发生。但是当我将 java -jar c:/dir/filename.jar 写入 cmd 时,它可以工
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
如何让该 Java 代码在 Eclipse 之外运行? import java.util.*; public class Calculations { public static void main(
今天我第一次启动 jar 文件时遇到问题。现在我知道(解压 jar 后)当我在 Eclipse 中导出并创建程序的 jar 包时,文本文件并没有出现。 为什么文本文件没有与类文件一起出现?我应该将它们
我不知道为什么,但是当我将项目导出到可执行 jar 文件时,有些东西并不像从 eclipse 运行程序一样。一帧不会打开,其中只包含文本。我有另一个内部框架,它是一个分割 Pane ,包含右侧面板上的
我是一名优秀的程序员,十分优秀!