Paypal API with PHP and cURL(带有 PHP 和 cURL 的 Paypal API)
问题描述
我正在尝试按照 Paypal API 文档所述的第一次调用".这是我遵循的示例:
I'm attempting "the first call" as outlined by the Paypal API documentation. This is the example provided that I'm following:
curl https://api.sandbox.paypal.com/v1/oauth2/token
-H "Accept: application/json"
-H "Accept-Language: en_US"
-u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp"
-d "grant_type=client_credentials"
我已经在 PHP 中构建了一个 curl 实例,除了最后一个之外,还有上述所有标头.-d
标志在 PHP 中转换为 curl 选项是什么?据我所知,那里几乎没有解释.我设法将 -u
推断为 CURLOPT_USERPWD
.
I have constructed a curl instance in PHP with all the above headers apart from the last one. What does a -d
flag convert to as a curl option in PHP? There is little explanation there as far as I can tell. I managed to deduce -u
as CURLOPT_USERPWD
.
推荐答案
经过一番周密的摸索,我将开发人员的部分内容与其他问题拼凑在一起.我使用以下代码成功获得了访问令牌:
Having a good trawl around I pieced together parts from developers with other problems. I successfully gained my access token using the following code:
<?php
$ch = curl_init();
$clientId = "myId";
$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_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);
?>
这篇关于带有 PHP 和 cURL 的 Paypal API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 PHP 和 cURL 的 Paypal API


基础教程推荐
- PHP 守护进程/worker 环境 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01