免费代理oAuth2可以';t使用轻型PHP包装器更新联系人
我在FreeAgent中创建新联系人时遇到问题 我正在为oAuth2.0协议使用轻型PHP包装器,并成功地设置了oAuth2。我可以连接到FreeAgent并成功检索客户列表。到目前为止,一切顺利。我遇到的问题是以另一种方式发回数据,即在FreeAgent中创建新联系人 以下是我尝试过的一些代码:免费代理oAuth2可以';t使用轻型PHP包装器更新联系人,php,oauth-2.0,Php,Oauth 2.0,我在FreeAgent中创建新联系人时遇到问题 我正在为oAuth2.0协议使用轻型PHP包装器,并成功地设置了oAuth2。我可以连接到FreeAgent并成功检索客户列表。到目前为止,一切顺利。我遇到的问题是以另一种方式发回数据,即在FreeAgent中创建新联系人 以下是我尝试过的一些代码: require_once($_SERVER['DOCUMENT_ROOT'].'/OAuth2/Client.php'); require_once($_SERVER['DOCUMENT_ROOT']
require_once($_SERVER['DOCUMENT_ROOT'].'/OAuth2/Client.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/OAuth2/GrantType/IGrantType.php');
$client = new OAuth2\Client($clientid, $secret);
$params = json_encode(array('contact' => array('first-name' => $firstname_unencrypted, 'last-name' => $surname_unencrypted)));
$response = $client->fetch("/contacts", $params, "POST", array('User-Agent' => 'MyApp', 'Accept' => 'application/json', 'Content-type' => 'application/json'));
var_dump($response);
返回的var_转储显示:
array(3) {
["result"]=>
bool(false)
["code"]=>
int(0)
["content_type"]=>
bool(false)
}
我很确定我在做傻事。我尝试用XML而不是JSON发送。我尝试只使用单个参数数组,而不是示例中的数组中的数组。我在兜圈子
如果有人能给我一个正确的方向,我将永远感激 有效的示例代码:
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<contact>
<first-name>$firstname_unencrypted</first-name>
<last-name>$surname_unencrypted</last-name>
</contact>";
if ($sandbox || $demo)
$ch = curl_init('https://api.sandbox.freeagent.com/v2/contacts');
else
$ch = curl_init('https://api.freeagent.com/v2/contacts');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$freeagentaccesstoken,
'Content-Type: application/xml',
'Accept: application/json',
'User-Agent: MyApp',
'Content-Length: ' . strlen($xml))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//execute post
$result=json_decode(curl_exec($ch), true);
$freeagenturl=$result['contact']['url'];
curl_close($ch);
$xml=”
$firstname\u未加密
$LANSAME\u未加密
";
如果($sandbox | |$demo)
$ch=curl\u init('https://api.sandbox.freeagent.com/v2/contacts');
其他的
$ch=curl\u init('https://api.freeagent.com/v2/contacts');
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,“POST”);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,数组(
“授权:持有人”。$freeagentaccesstoken,
'内容类型:应用程序/xml',
'接受:应用程序/json',
'用户代理:MyApp',
“内容长度:”.strlen($xml))
);
curl_setopt($ch,CURLOPT_超时,5);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
//执行职务
$result=json_decode(curl_exec($ch),true);
$freeagenturl=$result['contact']['url'];
卷曲关闭($ch);
我正在使用CURL,现在在这方面取得了一些进展,但仍然出现了一个错误。我会进一步调查,如果我找到了解决方案,我会把它贴在这里……是的,CURL工作得很好。我早该想到的。站起来!!