views:

1386

answers:

1

Hey guys,

I have been extracting information from the iTunes App Store for the past couple of weeks using a script I found and modified. Everything was working fine until a couple days ago when I realized that no XML was being generated anymore. Here is the code for the script that generates the XML:

<?php
header("Content-type: text/plain"); 
ini_set('display_errors', false);

if(isset($_GET['appID']))
{
 $appID = (int)stripslashes($_GET['appID']);

 $url = "http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=" . $appID . "&mt=8";

 $useragent = "iTunes/9.0.2 (Macintosh; Intel Mac OS X 10.5.8) AppleWebKit/531.21.8";
 $header = array("X-Apple-Store-Front: 143441-1");

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_FAILONERROR, 1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
 curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

 $result = curl_exec($ch);

 curl_close($ch); 

 echo $result;
}
?>

So I added the HTTPHEADER option to no avail, but the kicker is that it works perfectly well when I go to Terminal and type this:

curl -s -A "iTunes/9.0.2 (Macintosh; Intel Mac OS X 10.5.8) AppleWebKit/531.21.8" -H "X-Apple-Store-Front: 143441-1" 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=339038562&amp;mt=8'

It returns the XML that I need, but why won't the PHP script work?

Appreciate any help!

+2  A: 

Works fine for me. Here are few things to think about:

  • Are you sure $GET['appID'] is set? Perhaps the script is being run via a POST?
  • Comment out ini_set('display_errors', false); and see if any notices/warnings/errors appear.
  • Is the script running on the same box as the curl command line?
Mike
I just noticed I was making a mistake with the URL all along but that still isn't the issue - it still seems to hang when I run this.I've commented out that line you mentioned, as well as the 'isset' line, and it seems to hang!But no, the script is running off of my server and I ran the curl command line off of Terminal on my Macbook.Thanks for looking into it it though, I'll try to use one of my local servers and check again!
JonLim
Nevermind, I was editing a local file.Would never have noticed the whole... not using 'appID' in my URL if it weren't for you, thanks! :)
JonLim
Happy to help. Sometimes all a problem needs is another set of eyes.
Mike