使用curl和json解码。我可以获取用户所有YouTube视频的列表。它完美地运作。服务器忙时,Curl返回NULL。请建议我解决这个问题
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, 'http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?v=2&alt=jsonc&max-results=30);
$output = curl_exec($curl);
curl_close($curl);
$json = json_decode($output,true);
这是我用来获取视频的代码。当服务器忙时,它返回NULL。
答案 0 :(得分:1)
我建议您在API调用中使用开发人员密钥。因为我认为此问题可能与YouTube API配额错误有关。您可以从this blog获取更多信息。你应该注意这些引用的文字:
The new quota system ties usage to a specific developer key; as long as your application includes a developer key along with your YouTube API requests, your requests will be less likely to be flagged for quota violations.