【发布时间】:2015-03-26 21:50:43
【问题描述】:
嗨,
我已经在 Paypal 设置了一个企业帐户,而且我似乎已经有了我的测试 API 凭据,因为我可以从我的 Sandbox 帐户中成功检索它们。
现在我正在尝试进行“第一次调用”以获取授权令牌。
这是我的 PHP 代码:
$ch = curl_init();
$clientId = "myid"; //not the actual one
$secret = "mypass"; //not the actual one
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, "Accept: application/json");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
$json = json_decode($result);
print_r($json);
curl_close($ch);
以下是回复:
stdClass Object ( [error] => invalid_client [error_description] => Invalid client credentials )
有人知道吗?
谢谢
编辑:此登录有效(我在其他地方找到):
clientId:ASF6RRBP0uTq7FnC90tpFx7vfA-Pliw8uQDjv5RZ10Y_NVspuc88pUPLN6yM
秘密:EAdx7BDKzWczDomYG2QDHu8jhaAXj4xDZLHadvL5aRfesjwo5c81zbSpRxuE
奇怪的是格式看起来和我的很不一样。
我被困在这里,没有令牌无法继续前进。
【问题讨论】:
-
您确定使用沙箱凭据,因为您的端点是沙箱。?确保 $clientid 和 $secret id 之间没有空格
-
使用该类方法处理您的paypal提供的付款。 github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php
-
vimal:我从沙盒/帐户中检索了我的凭据,用户名类似于 name-facilitator_api1.mysite.com 并且密码是大写字母的散列,例如 BHTG9GM38NQ4XGW6; clientid 和 pass 之间只有一个“:”
标签: php curl paypal paypal-sandbox