Reputation: 43
I am trying to use Postman to do a get request to get tweets from a specific User. I've followed Twitters documentation and created a Bearer Token with Postman but I am still receiving a 400 error. There are no details to this error it just say bad request.
Is the Client Id and Client Secret = My Consumer Api Key and my Consumer Api Key Secret? Or is this my Access Token and Access Token Secret?
I am then making a get request to https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterdev&count=1
Upvotes: 2
Views: 850
Reputation: 1717
Once you have a Bearer token, the process is much simpler than what you show in your question.
To make it easier for others to follow this answer, below is the complete process.
You've done some of this already, so feel free to skip to MAKE A REQUEST TO TWITTER WITH A BEARER TOKEN USING POSTMAN.
Note: I am using Postman 7.1.1, but I know for a fact that all of what I show here is possible with prior versions as well (though the labels for Authorization, etc might be slightly different.)
For those that might want to follow along but are not as far along as the user asking the question, here is how to catch up:
Create a postman request as follows:
Let's call out the various parts of this request:
Once you have it set up like the above, Send this request and note the response, which should be in the form:
{
"token_type": "bearer",
"access_token": "AAAAAAAAAAAAAAAAAAAAAE3Q%SOMEoLONGoTOKENoHEREoHEREoHEREoHEREoLxTx4xddH50oSOMEoLONGoTOKENoHEREoHEREoHEREoHEREoPxsd3x"
}
(The above is not a real token and the words are for illustration only. Your token will be gibberish.)
With all of the preparation out of the way, we're ready for the direct answer to @Kiyana's question.
Now that you have a Bearer token making the actual request to an endpoint that supports this authorization type is pretty simple. (Note that not all of Twitter's endpoints might support this. Refer back to the above link on Bearer Tokens for details.)
Create another postman request as follows:
Send this request and you should indeed receive back the response you're interested in!
As a bonus answer here, in the examples above, we used the Authorization tab for Postman. However, all that this tab does is that it adds the proper request headers to your request. If you don't want to use the Authorization tab you can just add headers to your request instead!
I won't get into the details of how to do the first one (the Basic Auth with username/password) because it's a little involved.
However, in the second case, the header for a bearer token is very simple. The header that is added is simply called Authorization
and the value that is passed there is simply the string "Bearer", plus space then your token.
For example:
Authorization: Bearer AAAAAAAAAAAAAAAAAAAAAE3Q%SOMEoLONGoTOKENoHEREoHEREoHEREoHEREoLxTx4xddH50oSOMEoLONGoTOKENoHEREoHEREoHEREoHEREoPxsd3x
Upvotes: 3