我正在尝试使用UrlFetchApp将此代码转换为google应用程序脚本,我没有运气,也无法在线找到太多帮助。
curl -v -X GET https://api.sandbox.paypal.com/v1/activities/activities?start_time=2012-01-01T00:00:01.000Z&end_time=2014-10-01T23:59:59.999Z&page_size=10 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token"
任何帮助或方向,学习如何做到这一点将非常感激。这是代码,我试过:
function myFunction() {
var tokenEndpoint = "https://api.sandbox.paypal.com/v1/activities/activities?start_time=2018-01-01T00:00:01.000Z&end_time=2018-04-01T23:59:59.999Z&page_size=10";
var head = {
'Authorization':"Bearer " + "<token>",
'ContentType': 'application/json'
}
var params = {
headers: head,
}
var request = UrlFetchApp.getRequest(tokenEndpoint, params);
var response = UrlFetchApp.fetch(tokenEndpoint, params);
var result = response.getContentText();
Logger.log(result);
var resultObject = JSON.parse(result);
}
答案 0 :(得分:-1)
尝试这样的事情
function sampleGet() {
var headers = {
'Authorization': 'Bearer' + access_token,
};
var options =
{
"method" : "get",
"headers": headers,
"contentType": "application/json",
};
var result = UrlFetchApp.fetch('https://api.sandbox.paypal.com/v1/activities/activities?start_time=2012-01-01T00:00:01.000Z&end_time=2014-10-01T23:59:59.999Z&page_size=10', options).getContentText();
Logger.log(result);
}