google-apps-script - Google Apps 脚本中的 PayPal REST API 错误 400
问题描述
我正在尝试使用 PayPal API为我的OnlyFans应用程序创建订阅。
我使用与使用 Postman 时完全相同的身体。
不知何故,我可以使用 Postman 获得响应,但尝试通过应用脚本执行此操作时遇到此错误。
我已经对任何尾随逗号等进行了三重四重检查。
似乎在格式中找不到任何错误。
为什么我收到错误代码 400?
"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect...
function restCall (){
var restEndpoint = "https://api-m.sandbox.paypal.com/v1/billing/subscriptions"
var head = {
"Authorization":"Bearer "+ TokenProperties.getAccessToken(),
"Content-Type": "application/json",
"PayPal-Request-Id": "1111-1111-1111-1111"
}
var postPayload =
{
"plan_id": "P-09E19660L3543673CMETTBBA",
"subscriber": {
"name": {
"given_name": "John",
"surname": "Doe"
},
"email_address": "sb-y9erz7310462@personal.example.com"
},
"application_context": {
"brand_name": "Test",
"user_action": "SUBSCRIBE_NOW",
"payment_method": {
"payer_selected": "PAYPAL",
"payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
},
"return_url": "https://example.com/returnUrl",
"cancel_url": "https://example.com/cancelUrl"
}
}
var params = {
headers: head,
method: "POST",
payload : postPayload
}
var response = UrlFetchApp.fetch(restEndpoint, params);
}
解决方案
尝试
var options = {
"contentType": "application/json",
"method": "post",
"headers": head,
"payload": JSON.stringify(postPayload)
};
推荐阅读
- janusgraph - Janusgraph:无法使用 cql 后端打开图形
- c - 多维数组的形式参数
- c++ - 我刚刚开始学习使用 C++ 的链表。我正在尝试使用向量创建一个链表。为什么这段代码有问题?
- python - Python中自恋数字检查中的意外输出
- c# - 如何防止最终用户通过 C#/.NET 中的过度发布攻击通过其主键修改对象?
- javascript - html2canvas - 错误:元素未附加到文档
- java - 如何设置 HttpClient 代理?
- java - Spring cloud Kafka 流的反序列化问题导致:java.lang.ClassCastException:ClassName 无法转换为 ClassName
- python - 如何减少此代码的内存负载?
- typescript - 我应该直接导出路由器还是作为 TypeScript NodeJS 中的类的实例?