我已經創建了一個變數來保存客戶ID(CLIENT_ID),但我一直得到一個錯誤資訊,說運行這個函式時需要客戶ID。有誰知道我在這里做錯了什么嗎?
function getAuth() {
var authBasedUrl = 'https://test-api.service.hmrc.gov.uk/oauth/authorize'/span>;
var response = UrlFetchApp.fetch(authBasedUrl, {
headers: {
'Accept' : 'application/vnd.hmrc.1.0 json'。
'response_type': 'code',
'client_id' : CLIENT_ID,
'scope' : 'hello'。
'redirect_uri' : 'https://www.xxxxxxx.com/'.
}});
var result = JSON.parse(response.getContentText() )。)
Logger.log(JSON. stringify(result, null, 2)。
}
uj5u.com熱心網友回復:
基于docs,你需要做一個POST請求。頁面上有一個blockqoute,上面寫著:
將請求引數包含在請求正文中,而不是作為請求標題。 headers.
編輯:
function getAuth(){
var authBasedUrl = 'https://test-api.service.hmrc.gov.uk/oauth/token'/span>;
var options = {
headers: {
'Accept': 'application/vnd.hmrc.1.0 json',
"Content-Type": "application/json"。
},
payload: JSON.stringify( {
client_id: 'RgwU6hvdxxxxxxic6LwIt'。
client_secret: '9e8c9yyyyyyc2fc2ed9126'。
grant_type: 'client_credentials'。
scope: 'hello'.
})
}
var response = UrlFetchApp.fetch(authBasedUrl, options)。
var result = JSON.parse(response.getContentText)。
console.log(result)。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/319351.html
標籤:
上一篇:如何在谷歌應用腳本中使用靜態方法
下一篇:谷歌腳本--API頭檔案
