2012-01-21 21 views
-1

我试图编写代码,它将返回包含当前Twitter上的趋势标签的100条推文。首先,我得到的当前趋势的内容和隔离只是趋势主题标签:使用它的关键字将数组值存储到新变量 - twitter api

$json_output=json_decode(file_get_contents("https://api.twitter.com/1/trends/23424977.json"),true); 
print_r($json_output); 
foreach($json_output[0]['trends'] as $trend) { 
    if ($trend['name'][0] === '#') { 
     echo $trend['name']; 
     $hashtag == $trend['name']; 
    } 
} 

但是,而不是附和潮流[“名”],我想用它使用Twitter搜索方法进行搜索。通过添加这样的事情,如果语句中:

$past_uses = json_decode(file_get_contents("http://search.twitter.com/search.json?q="$hashtag"&rpp=100&include_entities=true&result_type=popular"),true); 

但变量$#标签没有被正确定义,我不知道为什么。 (当我试图回显$ hashtags时,检查它是否存储了适当的值,它不会打印任何内容。)那么,我应该更改什么,以便URL中可以使用$ trend ['name']的值搜索方法,以获得包括热门话题标签在内的过去推文?

谢谢!

回答

0

您正在做比较而不是分配$ hashtag。

$hashtag == $trend['name']; 

这基本上只是说false内联。相反,使用单个等号:

$hashtag = $trend['name']; 

而且,你的$ past_uses,请确保您连接以点串正确:

$past_uses = json_decode(
    file_get_contents("http://search.twitter.com/search.json?q=" . $hashtag . "&rpp=100&include_entities=true&result_type=popular"), 
true); 
+0

*捂脸*我完全应该已经注意到,我写的错误。非常感谢!现在正在工作。 :) – Jennifer