【发布时间】:2020-06-09 15:03:49
【问题描述】:
大家好,我正在研究 google apps-script Api。
import 'package:flutter/material.dart';
import 'package:googleapis/script/v1.dart';
import 'package:googleapis_auth/auth_io.dart';
class ApiTest extends StatefulWidget {
@override
_ApiTestState createState() => _ApiTestState();
}
class _ApiTestState extends State<ApiTest> {
var accountCredentials = new ServiceAccountCredentials.fromJson({
"type": "service_account",
"project_id": "xxxxxxxxx",
"private_key_id": "xxxxxxxxxxxxxxx",
"private_key":
"-----BEGIN PRIVATE KEY-----\nMIIExxxxxxxxxxxxxxxxDJlUBIRuMwo=\n-----END PRIVATE KEY-----\n",
"client_email": "xxxxxxx@yyyyyy.iam.gserviceaccount.com",
"client_id": "0000000000000",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url":
"https://www.googleapis.com/robot/v1/metadata/x509/xxxxxxx%40yyyyyy.iam.gserviceaccount.com"
});
List<String> scopes = [
"https://www.googleapis.com/auth/documents.currentonly",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/script.storage",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/script.send_mail",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/sqlservice"
];
@override
void initState() {
super.initState();
main();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.white,
child: Center(child: Text("Hello Worlds")),
),
);
}
void main() {
clientViaServiceAccount(accountCredentials, scopes).then((http_client) {
var service = new ScriptApi(http_client);
ExecutionRequest request = new ExecutionRequest();
request.function = "projectSummary";
service.scripts.run(
request, "1C9zxs82nICdyH_O8BMIU9vLpFLmDIZmzw5-3HVnJRvusrr8zMa8nIKXV");
});
}
}
我已经完成了。
- 将脚本项目部署为 API 可执行文件。
- 为执行提供适当范围的 OAuth 令牌。
- 确保脚本和调用应用程序共享一个公共云平台 (GCP) 项目。
- 启用 Google Apps 脚本 API
我得到响应:- 状态:403,消息:调用者没有权限
请指导我为什么会出现此错误。
【问题讨论】:
-
脚本文件的共享权限是什么?此外,谁拥有该脚本以及您在 dart 项目的 OAuth 流程中使用谁的凭据?
标签: android flutter dart google-api