【发布时间】:2016-09-12 17:33:07
【问题描述】:
您好,我正在使用其他人使用的代码,这些人据说已经让它工作并检索了他们的令牌信息。代码如下:
$ch = curl_init();
$clientId = "myclientid";
$secret = "mysecret";
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
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);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
print_r($json->access_token);
}
curl_close($ch); //THIS CODE IS NOW WORKING!
我从Paypal API with PHP and cURL 检索到此代码,并看到它在其他一些人的代码中实现,所以我认为它可以工作。但是,即使我提供了正确的客户端 ID 和密码,我也没有收到任何响应(也许最近的更新破坏了此代码?)。
Paypal 提供的获取访问令牌的指南可在此处找到-> https://developer.paypal.com/docs/integration/direct/make-your-first-call/ 但是它演示了 cURL 中的解决方案,而不是通过 PHP cURL 扩展,所以它对我来说有点神秘。有什么帮助吗?
【问题讨论】: