【问题标题】:PHP PayPal REST API authorization callPHP PayPal REST API 授权调用
【发布时间】:2014-08-23 15:03:56
【问题描述】:

我正在尝试使用 PHP 和 cURL 从 PayPal 请求身份验证令牌以创建付款。

我的代码是:

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept: application/json',
    'Accept-Language: en_US'
    ));

curl_setopt($ch, CURLOPT_USRPWD, 'xxxx:xxxx');

curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');

$output = curl_exec($ch);

?>

我得到了回应:

curl_setopt() expects parameter 2 to be long, string given in Users/anth/sites/abyss/auth.php on line 11
{"error":"invalid_client","error_description":"Invalid client credentials"}

第 11 行是:

curl_setopt($ch, CURLOPT_USRPWD, 'xxxx:xxxx');

我已经检查了我的客户 ID 和密码,它们都很好。

有谁知道我是不是使用了错误的语法?

谢谢

【问题讨论】:

    标签: php api rest curl paypal


    【解决方案1】:

    您使用了 curl_setopt($ch, CURLOPT_USRPWD, 'xxxx:xxxx') 而不是 curl_setopt($ch, CURLOPT_USERPWD, 'XXXX:XXXX'); .请注意错过的 'E' ,除此之外,您还需要添加一行: curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    所以修正后的版本如下:

     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Accept: application/json',
        'Accept-Language: en_US'
        ));
    curl_setopt($ch, CURLOPT_USERPWD, 'XXXX:XXXX');
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $output = curl_exec($ch);
    print_r($output);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 2014-03-09
      • 2015-09-13
      • 1970-01-01
      • 2014-05-09
      相关资源
      最近更新 更多