我在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>
答案 0 :(得分:0)
响应包含重定向(状态代码307):
http://cdn-api.netflix.com/api/v3/current/Catalog2/en_US.xml?token= {}。
您需要向该网址发出第二个请求(使用响应中提供的令牌)来获取数据。