我使用 Netflix 网站上的教程正确下载了特定电影的 API 查询的 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>