user1406716
user1406716

Reputation: 9705

How to make a REST GET call to Twitter API?

beginner alert - first time using a REST API

In my application, I am expecting to receive back a JSON object. My problem: what is the URL in the browser that I enter to receive a JSON object.

I tried the following URL: "https://api.twitter.com/1.1/search/tweets.json?q=%40twitterapi" (given at https://dev.twitter.com/docs/using-search) but I get the following output: {"errors":[{"message":"Bad Authentication data","code":215}]}

How I provide authentication data here?

I also tried to use the Console here: https://dev.twitter.com/console

I am able to get a successful reply (JSON data) when the "Request" is this. My question is - How do I make the "GET" request command into the format of "https://api.twitter.com/1.1/....."???

GET /1.1/search/tweets.json?q=drupal HTTP/1.1
X-HostCommonName:
api.twitter.com
Authorization:
OAuth oauth_consumer_key="DC0sePOBbQ8bYdC8r4Smg",oauth_signature_method="HMAC-    SHA1",oauth_timestamp="1385673977",oauth_nonce="1397646198",oauth_version="1.0",oauth_token="1681790569-ZTfDb37AggcbOk3wgtoJeUeLbGd3I2SYnul2XKI",oauth_signature="Pr82%2FkF3RzmUE%2BJqWGEgyEMsiQo%3D"

Host: api.twitter.com X-Target-URI: https://api.twitter.com Connection: Keep-Alive

I may have asked two questions above (based on 2 things I have tried), but my goal is one only - how to get a JSON data back from the twitter API? (Also, please redirect me if this is not the right place for this question)

Upvotes: 0

Views: 2821

Answers (3)

GMLewisII
GMLewisII

Reputation: 366

While I'm not 100% sure about everything you are asking, I would suggest that you take a look at crafting your REST GET (and Posts) messages using a REST API Client such as Chrome's Advanced REST Client or FireFox's Rest Client to work out the kinks. These clients give you some basic fields to populate the data, allows you to test against a public REST API and you will able to see the URL that the client crafted.

Upvotes: 0

Sajad Deyargaroo
Sajad Deyargaroo

Reputation: 1149

To use Twitter API V1.1, you need to,

  • Create an app first, in Twitter
  • Get the Consumer key and Secret key
  • Then use them in your app

Please visit the Manage and create your applications link under REST API here.

Upvotes: 1

Robin Green
Robin Green

Reputation: 33063

You need to use OAuth.

Ask a vague question, get a vague answer. If you want me to be more helpful, you'll have to specify a programming language.

Upvotes: 0

Related Questions