-2

这个例子只为我显示了一个空白页。 这个也做了。 据我所知,我已经正确设置了最新版本的 PHP 和 cURL,所以那应该没有任何问题。我更喜欢 JavaScript 来检索产品,但我很开放。我碰巧技术不高,但我想踏入大门。

编辑:我将向您展示不起作用的代码,以及它给我的错误。

<?php

// Your developer key
$cj_id = "My ID - omitted for privacy.";


// Your website ID
$website_id = "Also removed for privacy.";

// Keywords to search for
$keywords = "credit+card";

// URL to query with cURL
$url = "https://product-search.api.cj.com/v2/product-search?website-id=$website_id&amp;keywords=$keywords";

// Initiate the cURL fetch
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Send authorization header with the CJ ID. Without this, the query won't work
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$cj_id));
$result = curl_exec($ch);

// Put the results to an object
$resultXML = simplexml_load_string($result);

// Print the results
print "<pre>";
print_r($resultXML);
print "</pre>";

?>

现在,这是它给我的错误。

SimpleXMLElement Object
(
    [error-message] => Invalid Key provided. Valid keys are: advertiser-ids, advertiser-sku, currency, high-price, high-sale-price, isbn, keywords, low-price, low-sale-price, manufacturer-name, manufacturer-sku, page-number, records-per-page, serviceable-area, sort-by, sort-order, upc, website-id
)
4

2 回答 2

0

您的 URL 有错误,请尝试以下操作:

$url = "https://product-search.api.cj.com/v2/product-search?website-id=$website_id&keywords=$keywords";

代替 :

$url = "https://product-search.api.cj.com/v2/product-search?website-id=$website_id&amp;keywords=$keywords";
于 2014-12-17T20:39:21.440 回答
0
<?php
                echo '<pre>';


                $url='https://product-search.api.cj.com/v2/product-search?website-id=your-id-key-here&advertiser-ids=4415206&records-per-page=999&serviceable-area=US';
                $CJ_KEY='0085eb59c8928f028ba5b27bccfe17cdd20cf4e9079b977b2cc6df72752abab9205676a2f7ee67befe9dccab85f656ef46aba49e500faccbf75dfc6e03f655334d/00848a3f9bf0e13525bce27f008d6245c3e42ae80f2d80a8d9d2220807ca386f4b10146cbbcfff06aafb5e49c03a3318213389dee7861abb2dd7229470390a89c9';

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, FAlSE);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$CJ_KEY));
                $curl_results = curl_exec($ch);
                $xml = simplexml_load_string($curl_results);

                var_dump($xml);


                // Loop Insert Product to database


                echo '<pre>';

// 如果没有设置:records-per-page=999,默认获取最新的50个产品 //advertiser-ids=4415206是CJ中的Advertiser的Id,可以替换其他的id,希望对你有帮助,祝你好运!

?>

于 2015-11-27T10:28:53.733 回答