This forum is now read-only. Please use our new forums! Go to forums
Twitter API Changed
It looks like http://search.twitter.com/search.json is outdated and the API v 1.1 changes it. I tried searching using https://api.twitter.com/1.1/search/tweets.json?q=ninja%20turtles but this didn’t seem to work.
This really isn’t a question, but more an issue.
NOTE, I used the second url based on what I gathered from this page: https://dev.twitter.com/docs/api/1.1/get/search/tweets
Answer 525ab076f10c604d74007f81
Answer 52f6988f8c1ccc29a70037bc
Yes it did. New version is 1.1 and it requires that you authenticate to issue API calls. To do this, you must:
- [create a new Twitter Application][1] using your Twitter account.
- Upon completion of step 1, go to the “API Keys” tab for your Twitter Application
- You will find the “API Key” (also known in Twitter authentication documents as the “Consumer Key”) and the “API Secret” (also known in Twitter authentication documents as the “Consumer Secret”).
- Follow [these instructions][2] to learn how to use your API Key & Secret to obtain a Bearer Token that you can include with your API requests.
- Copy your API Key and API Secret into the following format:
<API Key>:<API Secret>
- Use your favorite Base64 encoder to encode the string you created in step 5.
- Open curl and issue the following command, replacing ‘InsertYourBase64StringHere‘ with the string you generated in Step 6:
- Curl Command: curl ‘https://api.twitter.com/oauth2/token‘ –header ‘Authorization: Basic InsertYourBase64StringHere‘ –header ‘Content-Type: application/x-www-form-urlencoded;charset=UTF-8’ –data ‘
grant_type=client_credentials
‘ - You should receive back a JSON payload with your Bearer Access Token. Should look similar to this: {“token_type”:”bearer”,”access_token”:”AAAAAA89839948arAAAAasdqeAAP1AWAAAAAAAF0K28NbbSCGi38pp2kw1uH6tuf8%djjddjajkssaldasfjakslqwuiouerjakl2Y2uUCgN”}
- Use your new Access Token and replace “InsertAccessTokenValueHere“ with the token you received in Step 9: curl –get ‘https://api.twitter.com/1.1/search/tweets.json‘ –data ‘q=ninja+turtles’ –header ‘Authorization: Bearer InsertAccessTokenValueHere‘
- You will receive the JSON payload with Tweets that contained “Ninja Turtles”. You can then cut/paste this value into the script.js window to complete this exercise.
While this is a lot of effort, it is time well spent if you are interested in invoking 3rd party APIs, such as Twitter. Most APIs are moving to require authentication of some type, so this will become very common. It’s worth the extra 30-45 minutes to familiarize yourself with this process.
Hope this helps others.
Brian [1]: https://apps.twitter.com/app/new [2]: https://dev.twitter.com/docs/auth/application-only-auth
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
1 comments
Thank You!