curl - 使用 Parse.com 云代码确认 PayPal 付款

标签 curl paypal parse-platform

为了确认付款,我需要一个每 8 小时过期一次的 access_token,因此我需要在尝试验证付款之前使用云代码获取新的访问 token 。

我正在尝试使用 httpRequest:

function requestAccessToken(response){
        Parse.Cloud.httpRequest({
            method: 'POST',
            url: 'https://api.paypal.com/v1/oauth2/token',
            headers: {
                'Content-Type': 'application/json',
                'Accept-Language' : 'en_US'
            },
            body: 'grant_type=client_credentials',
            success: function(httpResponse) {
                var res = JSON.parse(httpResponse.text);
                response.success(res.access_token);
            },
            error: function(httpResponse) {
                response.error('requestAccessToken failed with response code ' + httpResponse.status);
            }
        });
    }

要执行以下 curl ( from docs ):

curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
  -H "Accept: application/json" \
  -H "Accept-Language: en_US" \
  -u "{client-ID}:{secret}" \
  -d "grant_type=client_credentials"

问题是我找不到将“{client-ID}:{secret}”添加到 httpRequest 的方法。

使用 url: 'https://'+clientId+':'+secret+'@api.paypal.com/v1/oauth2/token' 导致 500 服务器响应。

关于如何获取访问 token 以验证付款的任何想法?

最佳答案

您需要添加授权 header

      Authorization: Basic < {client-ID}:{secret}" encoded base64> (e.g. QWxhZGRpbjpvcGVuIHNlc2FtZQ==)

关于curl - 使用 Parse.com 云代码确认 PayPal 付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25964650/

相关文章:

php - 成功后带有重定向的 Paypal 立即购买按钮

transactions - 如何使用一些 API 下载 Paypal 交易

ios - Facebook 的最低权限-登录 Parse.com

java - 根据数据库属性返回 getItemViewType

Windows curl 批处理文件

json - 一次从 Perl JSON 获取单个键值

http - curl 转换为简单的 http 请求?

django - 使用Django商户异地处理功能消除经常性付款

ios - 在应用程序的 PFConfig 中存储 PFObject 指针

curl - 使用 Postman(或 cUrl)连接到移动服务(Azure)