【发布时间】:2011-10-15 00:08:23
【问题描述】:
大家好,我又回来了,在我的上一篇文章中,我试图使用 SOAP API (Integrating Dwolla with PHP with their API),但我发现 SOAP API 已被弃用,显然 Dwolla 有更有效的方式,例如 REST/oAuth2 .0 这就是为什么我今天在这里询问如何使用其余 API 已经快 2 周了,我真的很想学习这个。
首先我会说我已经成功地获得了一个 access_token 我这样做没有问题。问题是,当我尝试使用发送端点(https://www.dwolla.com/developers/endpoints/accountapi/send)时,基本上是在尝试向账户汇款。我的确切问题是我永远无法得到成功的回应;只有错误或错误消息响应。
所以在索引页面上我有“向您的帐户添加资金”链接。用户将单击该链接,它会将他们带到 Dwolla 页面,该页面将接受他们登录到他们的 Dwolla 帐户,然后接受网站要求的权限。用户按下“接受”后,它将重定向到我选择的所选 URL 并发送回 access_token 以用于授权目的。这是我的代码(这也是 Dwolla 重定向并发送 access_token 的页面)
<?php
//Define variables
$key = 'redacted';
$secret = 'redacted';
$dwolla_client_id = urlencode($key);
$dwolla_secret_key = urlencode($secret);
$code = urlencode($_GET["code"]);
//get token
$retireve_token = file_get_contents("https://www.dwolla.com/oauth/v2/token?client_id=".$dwolla_client_id."&client_secret=".$dwolla_secret_key."&grant_type=authorization_code&redirect_uri=http://localhost/purchase_order.php&code=".$code);
$decoded_json = json_decode($retireve_token, true);
var_dump($decoded_json);
if($decoded_json["access_token"]){
$arr = '{
"oauth_token": "'.$decoded_json["access_token"].'",
"fundsSource": "balance",
"pin": "1111",
"notes": "Payment for services rendered",
"amount": 1.01,
"destinationId": "812-111-1111",
"assumeCosts": false,
"facilitatorAmount": 0,
"destinationType": "dwolla"
}';
$opts = array('http'=>array('method'=>"POST",'content'=> $arr, 'header' => 'Content-Type: application/json'));
$ctx = stream_context_create($opts);
$send_request = file_get_contents('https://www.dwolla.com/oauth/rest/accountapi/send', false, $ctx);
var_dump(json_decode($send_request));
}
?>
例如,我会收到这样的消息
array(1) { ["access_token"]=> 字符串(50) “已编辑”} 警告: 文件获取内容(https://www.dwolla.com/oauth/rest/accountapi/send): 无法打开流:HTTP 请求失败! HTTP/1.1 503 服务 在第 47 行的 /home/swiftbitcoins/purchase_order.php 中不可用 NULL
【问题讨论】:
-
谢谢,我忘了:D
-
一切都好,我已经更新了我的凭据,旧的不再有效
-
根据您的日志,我认为您应该询问 dwolla。它说 503 服务不可用。这提供了服务器存在问题的线索。
-
Dwollas API 文档说任何错误都会导致断开连接。我已经能够使用相同的方法成功地执行 GET 请求,只有当我需要向服务器发送数据时它才不起作用,这是一个 POST 请求。
-
嗯,这是我在 Dwolla getsatisfaction.com/dwolla/topics/…987654324@ 上发布的“一个”帖子
标签: php api rest oauth-2.0 dwolla