File_get_contents和Curl什么都不返回

问题描述 投票:-1回答:1

我实际上正在使用Flickr api。我创建了我的Url请求,并将其发送到file_get_contents。一切都很好,但今天一切都坏了!

当我在浏览器上直接使用请求时,一切正常,但是当我使用文件获取内容或Curl时,它返回一个空变量。

这是我的代码示例:

$flickr_result = file_get_contents($request);

或者在卷曲上:

$cl = curl_init();
curl_setopt($cl, CURLOPT_URL, $url);
curl_setopt($cl, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($cl);

在我的php.ini上,allow_fopen_url是“On”。返回值不是false。

我真的不明白,一切都很好。

编辑

这就是curl_getinfo打印的内容:

[content_type] => text/html; charset=UTF-8 
[http_code] => 302 
[header_size] => 838 
[request_size] => 218 
[filetime] => -1 
[ssl_verify_result] => 0 
[redirect_count] => 0 
[total_time] => 0.312 
[namelookup_time] => 0 
[connect_time] => 0.015 
[pretransfer_time] => 0.015 
[size_upload] => 0 
[size_download] => 0 
[speed_download] => 0 
[speed_upload] => 0 
[download_content_length] => 0 
[upload_content_length] => 0 
[starttransfer_time] => 0.312 
[redirect_time] => 0 
[certinfo] => Array ( ) 
[primary_ip] => 69.147.76.173 
[primary_port] => 80 
[local_ip] => 127.0.0.1 
[local_port] => 51014 
[redirect_url] => https://flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXX&license=1,2,3,4,5,6&sort=interestingness-desc&text=toto&per_page=50&format=php_serial 
[request_header] => GET /services/rest/?method=flickr.photos.search&api_key=XXXXXX&license=1,2,3,4,5,6&sort=interestingness-desc&text=toto&per_page=50&format=php_serial HTTP/1.1 Host: flickr.com Accept: */* 
php curl file-get-contents flickr
1个回答
1
投票

编辑:现在看到您的curl输出,您将从API获得302重定向。

你不能使用file_get_content来解决这个问题,但是你可以建议curl遵循它自己的重定向:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

你有多少请求?也许你达到了配额 - 或者Flickr禁用了你的API密钥。


来自https://www.flickr.com/services/developer/api/

限制:由于Flickr API非常易于使用,因此也很容易滥用,这会威胁到依赖Flickr API的所有服务。为了防止这种情况发生,我们限制每个密钥对API的访问。如果您的应用程序在整个密钥上保持每小时3600次查询(这意味着您集成的所有用户的聚合),那么您将没事。如果我们检测到您的密钥滥用,我们将需要使密钥到期或关闭,以便为其他人(包括我们!)保留Flickr API功能。我们还会跟踪其他因素的使用情况,以确保没有API用户滥用系统。

© www.soinside.com 2019 - 2024. All rights reserved.