php - How do I save a gzipped copy of the Netflix instant catalog? -
i used tutorial on netflix's site correctly download gzip of api query specific movie. when changed code download gzip of entire netflix catalog, script doesn't work anymore.
when run script, api query ends "?output=json;" returns no results. when manually remove trailing semicolon, catalog downloads inside browser window. due size that's not option.
netflix tutorial: http://developer.netflix.com/page/resources/sample_php
my modifications:
<?php include ('oauthsimple.php'); $apikey = 'my key'; $sharedsecret = 'my secret'; /* code block works $arguments = array( term=>'fargo', expand=>'formats,synopsis', max_results=> '1', output=>'json' ); */ $arguments = array( output=>'json' ); //$path = "http://api-public.netflix.com/catalog/titles"; // original code movie search $path = "http://api-public.netflix.com/catalog/titles/streaming"; // full catalog search $oauth = new oauthsimple(); $signed = $oauth->sign(array(path=>$path, parameters=>$arguments, signatures=> array('consumer_key'=>$apikey, 'shared_secret'=>$sharedsecret ))); // go fetch data. $curl = curl_init(); curl_setopt($curl,curlopt_url,$signed['signed_url']); curl_setopt($curl,curlopt_httpheader,array('accept-encoding: gzip')); curl_setopt($curl,curlopt_returntransfer,1); curl_setopt($curl,curlopt_settimeout,2); $buffer = curl_exec($curl); if (curl_errno($curl)) { die ("an error occurred:".curl_error()); } curl_close($curl); //$result = json_decode($buffer); $fp = fopen('data.gzip', 'w'); fwrite($fp, $buffer); fclose($fp); ?> <p> <b>your signed url:</b></br> <?php print $signed['signed_url'] ?>; </p> <p> , output is:</br> <pre> <?php print print_r($buffer); ?> </pre> </p>
the response contains redirect (status code 307) to:
http://cdn-api.netflix.com/api/v3/current/catalog2/en_us.xml?token={}.
you need issue second request url (with token supplied in response) data.
Comments
Post a Comment