Search the web
Sign In
New User? Sign Up
ydn-php · Yahoo! PHP Developer Group (CLOSED)
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
noob help   Message List  
Reply | Forward Message #243 of 335 |
Re: noob help

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).
>





Thu Mar 20, 2008 5:50 pm

jrconlin
Offline Offline
Send Email Send Email

Forward
Message #243 of 335 |
Expand Messages Author Sort by Date

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...
brentan.alexander
brentan.alex...
Offline Send Email
Mar 20, 2008
5:28 pm

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...
JR Conlin
jrconlin
Offline Send Email
Mar 20, 2008
6:14 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help