How to fetch latest Twitter trends using PHP: Twitter API Part 2
This is the third article of Twitter API series. I already published article on Twitter Login with PHP and Tweet using PHP and Twitter API. In this article, I will tell you how to get latest trends of any location using Twitter API and PHP.
If you have not read the previous two articles of Twitter API, you must. It is because I will not repeat the process of obtaining the token and secret. These things are essential for using the API.
Twitter shows location based trends. So, you need to specify a location for getting the trends of that location. But it uses WOEID as location input. So, you need to know the WOEID of that location. You can use this link to search the WOEID of any city.
When you have WOEID, you can use the code given below to fetch the latest trends. This code will work only if you use same twitteroauth.php and config.php file.
$connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET, $row['token'], $row['secret']); $content = $connection->get('account/verify_credentials'); $r = $connection->get('trends/place', array('id' => '2295019'));
I have already explained how to obtain secret and token in the first tutorial. If you have not read that, you will find this code hard to understand.