UrlFetchApp令牌授权

问题描述 投票:-1回答:1

我正在尝试使用GScript的UrlFetchApp提取URL。该URL要求将令牌API密钥传递到请求标头中。

url = 'https://freshsales.io/search?q=abc';

var options = {
    'method' : 'get',
    'headers':{
      'Authorization': "Token token=XYZ"
    }
};
var response = UrlFetchApp.fetch(url, options);

这无法获得预期的响应,如下所示:

新鲜商品

window.NREUM ||(NREUM = {}); NREUM.info = {“ beacon”:“ bam.nr-data.net”,“ errorBeacon”:“ bam.nr-data.net”,“ licenseKey”:“ “,” applicationID“:” 33348835,33348834“,” transactionName“:” e11YEBQJXVlXER1LUllAVQxJFVRUQABaF0RdU0QHDg ==“,” queueTime“:1,” applicationTime“:30,” agent“:”“}

(window.NREUM ||(NREUM = {}))。loader_config = {xpid:“ VQcDVl5UDxADV1JWDwkEUw ==”,licenseKey:“”,applicationID:“ 33348835”}; window.NREUM ||(NREUM = {}) ,__ nr_require = function(t,n,e){函数r(e){if(!n [e]){varo = n [e] = {exports:{}}; t [e] [0] .call(o.exports,function(n){varo = t [e] [1] [n];返回r(o || n)},o,o.exports)}返回n [e] .exports} if(“ function” == typeof __nr_require)返回__nr_require; for(var o = 0; o0 &&(p- = 1)}),s.on(“内部错误”,function(t){i(“ ierr”,[t,c.now(),! 0])})},{}],3:[function(t,n,e){t(“ loader”)。features.ins =!0},{}],4:[function(t,n ,e){函数r(t){} if(window.performance && window.performance.timing && window.performance.getEntriesByType){varo = t(“ ee”),i = t(“ handle”),a = t(9),s = t(8),c =“ learResourceTimings”,f =“ addEventListener”,u =“ resourcetimingbufferfull”, d =“ bstResource”,l =“ resource”,p =“-开始”,h =“-结束”,m =“ fn” + p,w =“ fn” + h,v =“ bstTimer”,g = “ pushState”,y = t(“ loader”); y.features.stn =!0,t(7),“ addEventListener”在window && t(5); var x = NREUM.o.EV; o.on(m ,function(t,n){var e = t [0]; ex &&(this.bstStart = y.now())的实例),o.on(w,function(t,n){vare = t [0]; e instanceofx && i(“ bst”,[e,n,this.bstStart,y.now()])}),a.on(m,function(t,n,e){this.bstStart = y.now(), this.bstType = e}),a.on(w,function(t,n){i(v,[n,this.bstStart,y.now(),this.bstType])}),s.on( m,function(){this.bstStart = y.now()}),s.on(w,function(t,n){i(v,[n,this.bstStart,y.now(),“ requestAnimationFrame “]}}),o.on(g + p,函数(t){this.time = y.now(),this.startPath = location.pathname + location.hash}),o.on(g + h ,function(t){i(“ bstHist”,[location.pathname + location.hash,this.startPath,this.time])}),f在window.performance &&(window.performance [“ c” + c]?window.performancef:window.performancef),documentf,documentf,documentf}},{}],5:[function(t,n,e){functionr(t){for(varn = t; n &&!n.hasOwnProperty(u);)n = Object.getPrototypeOf(n); n && o(n)}函数o(t){s.inPlace(t,[u,d],“-”,i)}函数i(t,n){返回t [1]} vara = t(“ ee”)。get(“ events”),s = t(“ wrap-function”)(a,!0),c = t(“ gos”),f = XMLHttpRequest,u =“ addEventListener “,d =” removeEventListener“; n.exports = a,” getPrototypeOf“在对象?(r(文档),r(窗口),r(f.prototype)):f.prototype.hasOwnProperty(u)&&(o(window),o(f.prototype)),a.on(u +“ -start“,function(t,n){vare = t [1],r = c(e,“ nr @ wrapped”,function(){functiont(){if(“ function” == e.handleEvent的类型)返回e.handleEvent.apply(e,arguments)} var n = {object:t,“ function”:e} [typeofe];返回n?s(n,“ fn-”,null,n.name ||“ anonymous”):e}); this.wrapped = t [1] = r}),a.on(d +“-start”, function(t){t [1] = this.wrapped || t [1]})},{}],6:[function(t,n,e){functionr(t,n,e){var r = t [n];“ function” == r &&(t [n] = function(){vart = i(arguments),n = {}; o.emit(e +“ before-start”,[t],n); vara; n [m] && n [m] .dt &&(a = n [m] .dt); var s = r.apply(this,t);返回o.emit(e +“ start”,[t,a],s),s.then(function(t){returno.emit(e +“ end”,[null,t],s),t},function(t){抛出o.emit(e +“ end”,[t],s),t})})}} varo = t(“ ee”)。get(“ fetch”),i = t(22),a = t(21); n.exports = o; vars = window,c =“ fetch-”,f = c +“ body-”,u = [“ arrayBuffer”,“ blob”,“ json”,“ text”,“ formData”],d = s.Request,l = s.Response,p = s.fetch,h =“ prototype”,m =“ nr @ context”; d && l && p &&(a(u,function(t,n){r(d [h],n,f), r(l [h],n,f)}),r(s,“ fetch”,c),o.on(c +“ end”,function(t,n){vare = this; if(n){varr = n.headers.get(“ content-length”); null!== r &&(e.rxSize = r),o.emit(c +“ done”,[null,n],e)}其他o.emit(c +“ done”,[t],e)})}}},{}],7:[function(t,n,e){varr = t(“ ee”)。get(“ history”),o = t(“ wrap-function”)(r); n.exports = r; vari = window.history && window.history.constructor && window.history.constructor.prototype,a = window.history; i && i.pushState && i.replaceState &&(a = i),o.inPlace(a,[“ pushState”,“ replaceState”],“ -“)},{}],8:[function(t,n,e){varr = t(“ ee”)。get(“ raf”),o = t(“ wrap-function”)(r),i =“ equestAnimationFrame”; n.exports = r,o.inPlace(窗口,[“ r“ + i,” mozR“ + i,” webkitR“ + i,” msR“ + i],” raf-“),r.on(” raf-start“,function(t){t [0] = o(t [0],“ fn-”)}}},{}],9:[function(t,n,e){functionr(t,n,e){t [0] = a(t [0],“ fn-”,null,e)}函数o(t,n,e){this.method = e,this.timerDuration = isNaN(t [1])?0:+ t [1],t [0] = a(t [0],“ fn- “,this,e)} vari = t(“ ee”)。get(“ timer”),a = t(“ wrap-function”)(i),s =“ setTimeout”,c =“ setInterval”,f =“ clearTimeout”,u = “ -start”,d =“-”; n.exports = i,a.inPlace(window,[s,“ setImmediate”],s + d),a.inPlace(window,[c],c + d) ,a.inPlace(window,[f,“ clearImmediate”],f + d),i.on(c + u,r),i.on(s + u,o)},{}],10:[函数(t,n,e){函数r(t,n){d.inPlace(n,[“ onreadystatechange”],“ fn-”,s)}函数o(){vart = this,n = u.context(t); t.readyState> 3 &&!n.resolved &&(n.resolved =!0,u.emit(“ xhr-resolved”,[],t)),d.inPlace (t,g,“ fn-”,s)}函数i(t){y.push(t),h &&(b?b.then(a):w?w(a):( E = -E,O.data = E))}函数a(){for(var t = 0; t

我通过python测试了相同的代码(下面的代码),效果很好。

url = "https://freshsales.io/search?q=abe"

payload = {}
headers = {
  'Authorization': 'Token token=XYZ'
}

response = requests.request("GET", url, headers=headers, data = payload)

来自Python代码的响应:

[
    {
        "id": "1000705745",
        "name": "MKnight",
        "email": "[email protected]",
        "owner": {
            "id": 1000002014,
            "name": "Tim"
        },
        "updated_at": "2020-02-13T04:57:29Z",
        "primary_sales_account_name": "City of XYZ",
        "type": "contact"
    } ]

关于我可能在这里想念的任何想法?

google-apps-script urlfetch http-token-authentication
1个回答
2
投票

添加您可以接受的内容类型,以强制从服务器返回返回的内容类型:

headers:{
  Accept: "application/json",
  Authorization: "Token token=XYZ"
}
© www.soinside.com 2019 - 2024. All rights reserved.