【问题标题】:How do I save a gzipped copy of the Netflix instant catalog?如何保存 Netflix 即时目录的 gzip 副本?
【发布时间】:2013-03-28 15:08:48
【问题描述】:

我使用 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>

【问题讨论】:

    标签: php api curl gzip netflix


    【解决方案1】:

    响应包含重定向(状态代码 307)到:

    http://cdn-api.netflix.com/api/v3/current/Catalog2/en_US.xml?token={}。

    您需要向该 url 发出第二个请求(使用响应中提供的令牌)以获取数据。

    【讨论】:

      猜你喜欢
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 2022-12-06
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      相关资源
      最近更新 更多