15

I have a OAuth2 (bearer token), but how do I pass it to the endpoint? More precisely, how do I include the bearer token in the URL.

Example URL:

https://api.twitter.com/1.1/search/tweets.json?q=%23superbowl&result_type=recent

Example Bearer Token:

AAAAA5n0w5n0w5n0wMyL0ngBe4r4rT0k4n

How do I use my bearer token to authorize my requests?

Example Incorrect Usage:

https://api.twitter.com/1.1/search/tweets.json?q=%23superbowl&result_type=recent&bearer=AAAAA5n0w5n0w5n0wMyL0ngBe4r4rT0k4n

simhumileco
  • 31,877
  • 16
  • 137
  • 115
Mike
  • 151
  • 1
  • 1
  • 4

5 Answers5

30

You can do it in two equivalent ways:

  • by using the URL access_token parameter:

    https://base.url?access_token=f4f4994a875f461ca4d7708b9e027df4
  • or by adding the Authorization header:

    Authorization: Bearer f4f4994a875f461ca4d7708b9e027df4

Note: Whether two or only one of these methods works sometimes depends on the specific implementation of the web application (including the services and libraries used to create it).

simhumileco
  • 31,877
  • 16
  • 137
  • 115
3

https://YourApiUrl?access_token=0db69822-0d02-4c17-8c39-d3b818bee184

Append the valid bearer token as value to the key "access_token". This worked for me.

2

On Postman go to:

  1. Authentication tab
  2. Select type: Bearer Token
  3. Paste in your Token

If you want it in the URL too like you mentioned, just pass it in as parameter in the GET request.

Postman bearer token screenshot

thmspl
  • 2,437
  • 3
  • 22
  • 48
Ud0
  • 59
  • 6
0

Follow these steps:

  1. https://base.url and set the request type.
  2. Now under the url there is an Authorization tab --> click it.
  3. When you in the Authorization tab select the Authorization type and fill the required token fields.

You are using the OAuth 2.0 but there several more API Key / Bearer Token / ..

  1. Before sending the request Make sure to send a body if the request is waiting for a parameters.
  • Body tab under the url field --> click it.
  • Selected the required datatype none / form-data / raw / ..
  • If the raw datatype was selected make sure to select the schema-type

Text / javascript / JSON / HTML / XML

Here is a quick explaination video:

https://www.screencast.com/t/E3igDLQE

-3

example of use the authorization header in url

FYI,

https://Endpointurl?Authorization=Bearer 00D2w000000kc19!AQ0AQAXCu2pbsBn4YvKuvUbNieCGmG2CVL4lqVaJruAXKZYWuAQiuxtuMiOgvGw2KQ.E4CJtkOdUw0_Q7yUzQh_3XAgwWQfd

Hope you understood how to pass the token

Kamil Z
  • 181
  • 12
user6250770
  • 680
  • 2
  • 10
  • 25
  • https://i.imgur.com/4FOEIGd.png Trying but doesn't work. I'll just post the bearer token here. https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline {"token_type":"bearer","access_token":"AAAAAAAAAAAAAAAAAAAAAHRQBAEAAAAAqMqqfNPmB6PeWXagAaTHy0ZqkCI%3DTHEuxcGlH0LT13o6g3QpcwfJBZ7tVNqIMfEsjQMK0JQELijklR"} – Mike Dec 16 '19 at 12:48
  • https://Endpointurl?Authorization=Bearer AAAAAAAAAAAAAAAAAAAAAHRQBAEAAAAAqMqqfNPmB6PeWXagAaTHy0ZqkCI%3DTHEuxcGlH0LT13o6g3QpcwfJBZ7tVNqIMfEsjQMK0JQELijklR – user6250770 Dec 16 '19 at 13:14
  • Nope: https://api.twitter.com/1.1/search/tweets.json?q=superbowl&Authorization=Bearer%20AAAAAAAAAAAAAAAAAAAAAHRQBAEAAAAAqMqqfNPmB6PeWXagAaTHy0ZqkCI%253DTHEuxcGlH0LT13o6g3QpcwfJBZ7tVNqIMfEsjQMK0JQELijklR https://api.twitter.com/1.1/search/tweets.json?Bearer%20AAAAAAAAAAAAAAAAAAAAAHRQBAEAAAAAqMqqfNPmB6PeWXagAaTHy0ZqkCI%253DTHEuxcGlH0LT13o6g3QpcwfJBZ7tVNqIMfEsjQMK0JQELijklR – Mike Dec 16 '19 at 13:19
  • the code will expire every 10 minutes.. so pass updated code and check – user6250770 Dec 16 '19 at 13:20