2013-04-06 67 views
0

我在Netflix的網站上使用了一個教程,以正確下載特定電影的API查詢的gzip。當我更改代碼以下載整個Netflix目錄的gzip時,該腳本不再適用。如何保存Netflix即時目錄的gzip壓縮副本?

當我運行腳本時,API查詢以「?output = json;」結尾。這不會返回結果。當我手動刪除尾隨分號時,目錄會在我的瀏覽器窗口中下載。由於它的大小,這不完全是一種選擇。

Netflix的教程:http://developer.netflix.com/page/resources/sample_php

我的修改:

<?php 
include ('OAuthSimple.php'); 
$apiKey = 'MY KEY'; 
$sharedSecret = 'MY SECRET'; 

/* THIS 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 FOR 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 
            ))); 

// Now go fetch the 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> 
And the output is:</br> 
<pre> 
<?php 
print print_r($buffer); ?> 
</pre> 
</p> 

回答