PHP中的eBay API Oauth Refresh Token

时间:2017-11-14 09:23:36

标签: php curl oauth ebay-api

我目前正在尝试与eBay API集成,我已设法手动集成它并手动输入oAuth密钥来提取数据。

我生活中无法工作的是oAuth刷新令牌,我不断从API中获取最多的错误消息"出现错误,请再试一次"。

我目前的代码如下 -

    function GetTokens($sessionid){
            // Create headers to send with CURL request.
$headers = array
(
'Content-Type: application/x-www-form-urlencoded',
'Authorization: Basic REMOVED'
);

$xml =  '<?xml version="1.0" encoding="utf-8"?>'.
    '<FetchTokenRequest xmlns="urn:ebay:apis:eBLBaseComponents">'.
         '<SessionID>' . $sessionid . '</SessionID>'.

   '</FetchTokenRequest>';

// Send request to eBay and load response in $response
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $this->api_server . 
"/identity/v1/oauth2/token");
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_POSTFIELDS, $xml);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
    print_r($response);
} 

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

你至少可以不再骗API了。你告诉api i'm sending you some data in application/x-www-urlencoded format,然后以application/xml格式发送数据!也许这就是为什么你得到了神秘的错误。

你也应该抱怨他们的bugtracker,如果他们有错误,关于这个错误,错误应该更具描述性(例如,failed to parse the request body as appliation/x-www-urlencoded, malformed syntax以及http 400 Bad Request响应会很好)< / p>