【发布时间】:2019-09-08 06:31:40
【问题描述】:
我想通过关键字搜索获得项目。
<?php
error_reporting(E_ALL);
require_once("includes/config.php");
// Construct the HTTP GET call
$apicall = "https://api.ebay.com/buy/browse/v1/item_summary/search?"; //
URL to call
$apicall .= "q=GTR"; //search keyword
$apicall .= "limit=3";
// Create headers to send with CURL request.
$headers = array
(
'X-EBAY-API-APP-ID: ' . $sapp_id,
'X-EBAY-API-DEV-NAME: ' . $dev_id,
'X-EBAY-API-CERT-NAME: ' . $cert_id,
'X-EBAY-C-ENDUSERCTX: 5337984774'
);
// Send request to eBay and load response in $response
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL,
"https://api.ebay.com/buy/browse/v1/item_summary/search?");
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $apicall);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
// Load the call and capture the document returned by eBay API
$resp = $response;
// Output response
echo("<pre>");
print_r($resp);
//To retrieve specific values of the array in PHP, you will need to use
object operator
// $value = $resp->Item->ConvertedCurrentPrice;
// $value = $resp->Item->ConvertedCurrentPrice;
// print $xml->Product->Title;
echo("</pre>");
?>
我在运行时遇到了这个错误。
{
"errors": [
{
"errorId": 3001,
"domain": "ROUTING",
"category": "REQUEST",
"message": "Request Rejected",
"longMessage": "The Request has errors. For help, see the documentation for this API."
}
]
}
由于我是初学者,我不知道该怎么做。
我尝试了 xml 请求方法,它工作正常,但我想用 REST API 方法来做。
我关注这个文档 - Official eBay search api documentation
我想知道为什么我会收到此错误以及实现此搜索查询的正确方法是什么?
【问题讨论】:
-
在您的
curl_setopt($connection, CURLOPT_URL,行中,您是否应该使用您之前构建的$apicall的值? -
您构造的 url 看起来不正确 - 它应该更像
..../search?q=GTR&limit=3而不是..../search?q=GTRlimit=3?? -
查看文档developer.ebay.com/api-docs/buy/browse/resources/methods 建议要使用
search方法,您应该发出一个GET 请求,而您的curl 代码正在发送一个POST 请求。