Question Related to REST API

restapi
oauth

#1

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=20.9533951,75.9364752&radius=500&types=food&key=put_your_key_here

This is the URL of google maps api. Which returns json data if we pass the key at the last. and hit that url from our browser directly.
So is there anything like that in twitter as well? By which we can pass our consumer key or something like that at the end of link like this https://api.twitter.com/1.1/trends/available.json
Because without any tokens if we hit this URL then its giving error : Bad Authentication data Code : 215

Please help me. i am finding this from very long and have no luck.
Please Thank You So Much.


#2

You need to include authentication tokens in the header of the request. It’s not as simple as just adding a get parameter. I’d look into using a framework. If you tell me which language you’re developing in I can help point you towards one.


#3

I am developing in Android.
But the thing is that i want to see the JSON data in browser the way google maps’ link shows.
Are you getting what i am asking?


#4

Yes, I understand what you are asking. What I’m telling you is that it doesn’t work like that. As I said, you have to formulate a http request with authentication information in the headers.


#5

You could probably find some kind of REST API testing tool that enables you to add some Twitter OAuth tokens in the header, to retrieve the JSON data, if you really need it in a browser. If you’re building an app, I’d say that’s pretty unusual, as you’d want to consume the JSON in the application code. We provide Twitter Kit in Fabric to access the Twitter API on Android.


#6

Yeah thats what i am asking that what is the keyword to insert into url header.
just like google maps link key=your_key
So what is that for twitter api https://api.twitter.com/1.1/lists/statuses.json


#7

Yeah thats what i am asking that what is the keyword to insert into url header.
just like google maps link key=your_key
So what is that for twitter api https://api.twitter.com/1.1/lists/statuses.json
Help me with this because i am literally stuck into my app just because of this.


#8

When I say header I don’t mean a GET parameter. I mean you need to pass an Authorization header.

https://dev.twitter.com/oauth/overview/authentication-by-api-family


#9

But what i am asking is that what are the GET parameters for twitter.
Is it possible to pass GET parameters to get JSON data.


#10

Every response from Twitter is in JSON form. You can pass additional data via GET parameters but until you authenticate your requests with the authorization header, you won’t get anything besides that error message.


#11

Yeah i know that. i have created a twitter app too and have credentials too.
i tried this, https://api.twitter.com/1.1/lists/statuses.json?oauth_consumer_key=my_key
but got this
"code": 215,
“message”: “Bad Authentication data.”


#12

I can’t really be more clear about this. That isn’t how authentication tokens work for Twitter. You do not pass them in the url like that, they are set as headers.

https://dev.twitter.com/oauth/overview/single-user


#13

Can you give me a little example for that, how header works?
Because i am trying with passing my credentials to url.


#14

The difference is that Twitter’s REST API OAuth authentication requires the token in the HTTP header, not in the URL request parameters. I would try a tool like cURL or Postman to play around with getting your headers correct and loading the JSON data. But there is no way to just type in a URL into a browser and be authenticated.


#15

So can you tell me how i can get the json data using such tools?


#16

If you download Postman, type in the endpoint URL, select OAuth 1.0 for the authentication, enter in your consumer key and secret, your token and token secret, click “Add params to header”, and then Send.

Voila!


#17

If you are on Android, the best (in my opinion) way to interact with the Twitter API is to use Twitter Kit in Fabric, which can handle all of the authentication for you.