First off, I'd REALLY REALLY urge you not to use functions like open
or file_get_contents in PHP. They're security risks. Instead, you
should use things like CURL (see: http://blog.unitedheroes.net/curl/
for an easy tutorial)
Secondly (and probably related) the error you're getting back is
"user-agent not valid". The additional terms of service on the page state that
you must provide a valid browser User-Agent, and they even helpfully provide a
few examples. (Yes, I plan on pointing out the lunacy of this to them right
after I post this message.)
You can solve this problem in your code by passing a user agent string as part
of the request.
e.g.
<code>
// Your URL construction here.
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
//Lie to the service and say you're IE 7.
curl_setopt($curl,CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
$rawData = curl_exec($curl);
// Rest of your code.
</code>
I tested that out and not to my surprise, it works just fine.
Oh well, off to yell at the shopping folks.
--- In ydn-php@yahoogroups.com, "brentan.alexander"
<brentan.alexander@...> wrote:
>
> Hi all,
>
> im trying to write a site that uses a yahoo api to access product
> data...and as a first pass im just trying to create a test page that
> pulls data based on a upc I have on a box on my desk...anyways, the
> code i use is simply:
>
>
$yahooID="WQEKr67V34FYAoAdbaLr10PRTxYcHtWoOgv7yqPvJeTp5DEIh0A.cKuI3O_bi5fRnA4GSB\
nrd0g-";
> $upc="606449028423";
>
$url="http://shopping.yahooapis.com/ShoppingService/v2/CatalogListing?idtype=upc\
&idvalue=$upc&output=php&appid=$yahooID";
> echo "$url<BR>";
> $rawdata = file_get_contents($url);
> $data = unserialize($rawdata);
> print_r($data);
>
> The problem is it doesnt work! All it returns is this:
>
http://shopping.yahooapis.com/ShoppingService/v2/CatalogListing?idtype=upc&idval\
ue=606449028423&output=php&appid=WQEKr67V34FYAoAdbaLr10PRTxYcHtWoOgv7yqPvJeTp5DE\
Ih0A.cKuI3O_bi5fRnA4GSBnrd0g-
> Array ( [__notags] => The following errors were detected: [Message] =>
> Array ( [0] => User-agent not valid ) )
>
> Yet if I just copy that url into my browser window and go to it, it
> returns the results correctly and just fine...what am I doing wrong
> here??? (Ive copied and pasted the appid many times from the my yahoo
> page, and had new ones created, and disabled them and reenabled them,
> nothing works).
>