[英]Authorization request header in Appscript
I need to call API data in Appscript I have Token: ZjA2YmYwNjYtNzgxYy00ZThjLWFjZjktMjEwYjM1O I have URL: https://webexapis.com/v1/devices ?
如何使用鏈接驗證令牌。 如果我只調用 URL,我會收到以下錯誤
{"message":"The request requires a valid access token set in the Authorization request header.","errors":[{"description":"The request requires a valid access token set in the Authorization request header."}],"trackingId":"ROUTER_60ABA481-B37E-01BB-03DC-0AFDE82A03DC"}
需要將 Auth 令牌放入 header 中:
function makeRequest_(po) {
var options,r;
/*
po - A JSON object with the following settings
po.url - The url to make the request to
po.token - The Auth Token
po.method - POST or GET etc
*/
if (!po.url) {
console.error('No URL passed in. Parameters:' + JSON.stringify(po));
return;
}
options = {};
options.method = po.method;
options.headers = {Authorization: 'Bearer ' + po.token};
options.muteHttpExceptions = true;//Make sure this is always set
r = UrlFetchApp.fetch(po.url, options);
if (!r) {
console.error('ERROR - getting response' );
return;
}
//Logger.log('r.getResponseCode(): ' + r.getResponseCode());
if (r && r.getResponseCode() !== 200) {//There should always be a response unless the
//Fetch call failed
var arg = po ? JSON.stringify(po) :"po not passed in";
Logger.log('ERROR ' + r + '\npo:' + arg);
return false;
}
//Logger.log('r: ' + r)
return r;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.