我正在嘗試使用 API POST 請求將 Google 電子表格連接到 snov.io 服務,他們提供了一個 Python 代碼作為示例,我嘗試基于它運行下面的 google 腳本,但沒有成功。有任何想法嗎?謝謝 :)
Python(公司提供)
def get_access_token():
params = {
'grant_type':'client_credentials',
'client_id':'c57a0459f6t141659ea75cccb393c111',
'client_secret': '77cbf92b71553e85ce3bfd505214f40b'
}
res = requests.post('https://api.snov.io/v1/oauth/access_token', data=params)
resText = res.text.encode('ascii','ignore')
return json.loads(resText)['access_token']
Google Script(錯誤:SyntaxError:'意外的 JSON 輸入結束')
var params = {
'grant_type':'client_credentials',
'client_id':'c57a0459f6t141659ea75cccb393c111',
'client_secret': '77cbf92b71553e85ce3bfd505214f40b',
'method':'post'
}
var url = 'https://api.snov.io/v1/oauth/access_token';
var response = UrlFetchApp.fetch(url,params)
var json = response.getContentText();
obj = JSON.parse(json);
token = obj.result.access_token;
return token
uj5u.com熱心網友回復:
為了用您的python腳本實作相同的請求,如何修改您的Google Apps腳本如下?
修改后的腳本:
從:
var params = {
'grant_type':'client_credentials',
'client_id':'c57a0459f6t141659ea75cccb393c111',
'client_secret': '77cbf92b71553e85ce3bfd505214f40b',
'method':'post'
}
var url = 'https://api.snov.io/v1/oauth/access_token';
var response = UrlFetchApp.fetch(url,params)
到:
var params = {
'grant_type': 'client_credentials',
'client_id': 'c57a0459f6t141659ea75cccb393c111',
'client_secret': '77cbf92b71553e85ce3bfd505214f40b',
}
var url = 'https://api.snov.io/v1/oauth/access_token';
var response = UrlFetchApp.fetch(url, {method: "post", payload: params});
- 在這種情況下,即使
method: "post"被移除,也可以實作相同的請求。
參考:
- 獲取(網址,引數)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/358506.html
標籤:Python 谷歌应用程序脚本 邮政 urlfetch
下一篇:使用QT發布表單
