Php 通过文件获取内容通过标签获取推文
我试着用它来获取标签的推文 因为我只需要读取一个json文件,所以我使用了Php 通过文件获取内容通过标签获取推文,php,twitter,tweets,file-read,Php,Twitter,Tweets,File Read,我试着用它来获取标签的推文 因为我只需要读取一个json文件,所以我使用了file\u get\u contents而不是像这样的cURL file_get_contents('http://search.twitter.com/search.json?q=%23trends'); 但是,当我在本地主机中运行代码时,它显示以下错误。你知道吗 警告:文件获取内容(http://search.twitter.com/search.json)[function.file get contents]:
file\u get\u contents
而不是像这样的cURL
file_get_contents('http://search.twitter.com/search.json?q=%23trends');
但是,当我在本地主机中运行代码时,它显示以下错误。你知道吗
警告:文件获取内容(http://search.twitter.com/search.json)[function.file get contents]:无法打开流:找不到套接字传输“ssl”-您在配置PHP时是否忘记启用它?最好在任何情况下使用curl over FGC,FGC是本地文件除外 如果未启用本地主机上的curl
extension=php_curl.dll
(99.9%的活动主机已启用curl)
试试这个:
<?php
//Grab the twitter API with curl
$result = curl_get('http://search.twitter.com/search.json?q=%23trends');
//Decode the json result
//into an Object
$twitter = json_decode($result);
//into an Array
$twitter = json_decode($result,true);
//Debug
print_r($twitter);
function curl_get($url){
$return = '';
(function_exists('curl_init')) ? '' : die('cURL Must be installed!');
$curl = curl_init();
$header[0] = "Accept: text/xml,application/xml,application/json,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'TwitterAPI.Grabber (http://example.com/yoursite)');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($curl, CURLOPT_PROXY, 'http://proxy_address/');
curl_setopt($curl, CURLOPT_PROXYUSERPWD, 'username:password');
curl_setopt($curl, CURLOPT_PROXYPORT, 'portno');
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
?>
为什么1次投票不涉及主题??对于索厄尔来说,这似乎是一个非常有效的问题,我在localhost上启用了curl,是否要测试它?但是为什么这里curl比FGC好,我们只需要读取一个文件。我认为在这种情况下两者是相等的没有FGC只是fopen函数的包装器,对于远程操作,curl的速度接近两倍。比较:plus curl更健壮+1谢谢,我将使用curl!但是当我使用上面的curl代码时,它会显示我的大学局域网中使用的身份验证页面,即使我已经通过了身份验证!仍然在我输入凭据之后,它会重定向到localhost。你知道吗?这也许就是FGC需要ssl的原因,我不确定我能帮你,抱歉:s