This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Nathan
over 10 years

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

0 votes

Permalink

Same error.

points
over 10 years

Answer 52f6988f8c1ccc29a70037bc

0 votes

Permalink

Yes it did. New version is 1.1 and it requires that you authenticate to issue API calls. To do this, you must:

  1. [create a new Twitter Application][1] using your Twitter account.
  2. Upon completion of step 1, go to the “API Keys” tab for your Twitter Application
  3. 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”).
  4. 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.
  5. Copy your API Key and API Secret into the following format: <API Key>:<API Secret>
  6. Use your favorite Base64 encoder to encode the string you created in step 5.
  7. Open curl and issue the following command, replacing ‘InsertYourBase64StringHere‘ with the string you generated in Step 6:
  8. 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
  9. You should receive back a JSON payload with your Bearer Access Token. Should look similar to this: {“token_type”:”bearer”,”access_token”:”AAAAAA89839948arAAAAasdqeAAP1AWAAAAAAAF0K28NbbSCGi38pp2kw1uH6tuf8%djjddjajkssaldasfjakslqwuiouerjakl2Y2uUCgN”}
  10. 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
  11. 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

points
Submitted by Brian Pearson
about 10 years

1 comments

Beregszászi István about 10 years

Thank You!