Railway
Railway

Reputation: 71

How to use Twitter API?

I want to use twitter api without authentication. Is it possible? For example, I am going to get the user profile for certain user. Can I get his user profile without authentication?

Upvotes: 1

Views: 1163

Answers (3)

William
William

Reputation: 81

I just worked it out recently, hopefully this would be helpful for you.

First of all, it's impossible to "use twitter api without authentication" which makes sense in any aspects.

Secondly we need to know with what language you want to program with twitter API. Since you didn't mention anywhere in your question, I'd like to provide the solution with Java.
Below are the steps you need to follow to start using twitter APIs:

  1. Create your own X developer account on X developer portal(assuming you are to use free account)
  2. Create an project on the portal and a new app under the project
  3. Generate the credentials(consumer key, consumer secret, access key, access secret) for your account which is for calling the API with code on behalf of your own account
  4. Import this officially recognized library twittered(https://github.com/xdevplatform/twitter-api-java-sdk) into your java app
  5. Use the library method to build an Twitter instance with the credentials we got from the step 3 above
  6. Call the findUserById API(https://github.com/xdevplatform/twitter-api-java-sdk/blob/main/docs/UsersApi.md#finduserbyid) from the instance to get the information of the user you want to know

Summary

To be fair, the authentication of Twitter is a headache to handle as there are different permission for different APIs and plus there are OAuth 1.0 and 2.0 put in place at the same time...
However, if we take a step back and reuse the "wheels" built by others, we can actually easily start our own implementation right away!

Reference

  1. X Developer Portal: https://developer.x.com/en
  2. Twitter Developer Libraries(for all main stream languages): https://developer.x.com/en/docs/twitter-api/tools-and-libraries/v2
  3. My sample twitter bot app: https://github.com/william-ch3n/bot

Upvotes: 0

anon
anon

Reputation:

All Twitter API calls require the use of OAuth and a registered application with consumer key and token. They also require HTTPS.

A small number of API endpoints can be called without the use of a user context ("application-only" authentication). You can call the users/show.json endpoint with application-only authentication using a bearer token and no user context, but that will only work for public Twitter profiles, not protected ones.

Upvotes: 1

gautamaggarwal
gautamaggarwal

Reputation: 349

User authentication is mandatory. You also need to create a customer account and use the authentication for that.

You will also need to deal with api rate limiting by adding a small sleep time of around 60 seconds.

You can use this link to see some working code.

Upvotes: 2

Related Questions