Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query the Twitter 1.1 API using your granted oauth_token?

Tags:

oauth

twitter

api

The Twitter 1.1 API requires an OAuth token. My understanding of OAuth is that you need to request an authentication token using a cunsumer key, sectret, nounce, etc. Once you have received an OAuth token you should be able to access the API using ONLY that OAuth token.

When following the steps on Twitter I get examples on how to authenticate/sign the token, but I can't seem to find an example on how to access the (e.g. search) API with my oauth_token.

When executing the following GET request:

https://api.twitter.com/1.1/search/tweets.json?q=freebandname

I get (of course) a 'Bad Authentication data' response.

I would expect it would work when adding the granted OAuth token, but I have no idea how to do that.

Executing:

https://api.twitter.com/1.1/search/tweets.json?q=freebandname&oauth_token=aaaxx-xxx-xxx-xxxx

Also it returns a 'Bad Authentication data' response.

I also tried to pass only the oauth_token in the header, but this also returns a 'Bad Authentication data' response.

So basically my question is:

How do I request the Twitter 1.1 API with only your granted OAuth token?

like image 362
ceasaro Avatar asked Jun 13 '13 15:06

ceasaro


People also ask

How do I get OAuth token from Twitter API?

Step 1: getRequestToken () – sends the oauth_callback with the authentication header. It requests request_token and the secrete key from the Twitter API. Step 2: getOAuthVerifier () – redirects the user to the Twitter authentication page.

What are the authentication steps used in Twitter API?

An authentication step ensures access security on each API request. Twitter uses various authentication methods. Those are, OAuth 1.0a, OAuth 2.0 Bearer token, Basic authentication. I used OAuth 1.0a authentication to validate login with Twitter API requests. During the login flow, Twitter prompts to enter user credentials to login.

How to make a Twitter API request in Python?

To make any request to the Twitter API (in python or anywhere else) you require your API Key and Access Token. For this, you need to apply for a developer account with Twitter and have your account approved. Once approved, you can create a project and associate it with a sample App.

Does Twitter support OAuth login?

by Vincy. Last modified on December 27th, 2020. Almost all Internet giants (in good sense) like Google, Facebook, Twitter and LinkedIn support OAuth login. They provide API with detailed documentation to help developers integrate OAuth authentication. There are many client libraries available to implement Twitter OAuth login.


1 Answers

Well, I finally found the answer and it was pretty clear in the Twitter API 1.1 documentation. The documentation says you have to pass the token in the request header with the name 'Bearer'.

Everything is pretty clear explained here: https://dev.twitter.com/docs/auth/application-only-auth

For the implementation, scroll down to the 'Issuing application-only requests' section.

like image 97
ceasaro Avatar answered Oct 15 '22 11:10

ceasaro