【问题标题】:Confirming PayPal payment using Parse.com cloud code使用 Parse.com 云代码确认 PayPal 付款
【发布时间】:2014-11-15 20:42:03
【问题描述】:

为了确认付款,我需要一个每 8 小时过期的 access_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 服务器响应。

任何想法如何获取访问令牌来验证付款?

【问题讨论】:

  • 您是否有更多关于您收到的错误的详细信息?另外,您是否尝试过执行 curl 命令来验证您是否在其中得到了一些东西?
  • 如果您使用的是节点,您可能想看看officially supported node sdk 或看看它是如何工作的authorization

标签: curl paypal parse-platform


【解决方案1】:

需要添加授权头

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

【讨论】:

    猜你喜欢
    • 2015-01-19
    • 1970-01-01
    • 2016-08-22
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 2014-08-23
    相关资源
    最近更新 更多