如何通过带有身份验证的Google Apps脚本调用云功能?
我正在尝试使用"Hello World"云功能代码示例进行测试,但是当我调用它时,即使我已经将Invoker角色添加到请求者用户电子邮件中,也会出现401 HTTP错误.要运行此功能,我还需要对请求执行其他操作吗?
I'm trying to do a test with the "Hello World" Cloud Function code sample, but when I call it I get 401 HTTP error even I've already added the Invoker role to the requester user email. Is there anything else that I need to do on the request to run this function?
我正在Google脚本中尝试执行以下GET操作:
I'm trying to do the GET like this in Google Scripts:
function test(){
var url = 'https:******************/HelloWorld';
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText())
}
Python"Hello World"云函数代码示例为:
And the Python "Hello World" Cloud Function code sample is:
def hello_world(request):
"""Responds to any HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
The response text or any set of values that can be turned into a
Response object using
`make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
"""
request_json = request.get_json()
if request.args and 'message' in request.args:
return request.args.get('message')
elif request_json and 'message' in request_json:
return request_json['message']
else:
return f'Hello World!'
您可以成功浏览Cloud Functions端点吗?
Can you browse the Cloud Functions endpoint successfully?
https:******************/HelloWorld
在我的情况下(您可以尝试这样做),我的HelloWorld示例的URL使用默认的 function-1
名称,因此,我的URL为:
In my case (you may try this), my URL for the HelloWorld example used the default function-1
name, so my URL is:
https://us-central1-dazwilkin-200204-60062279.cloudfunctions.net/function-1
我使用上述网址创建了一个Apps脚本函数,并且可以正常工作:
I created an Apps Script function using the above URL and it works:
[20-02-04 10:44:18:857 PST] Hello World!