skip to Main Content

I’m trying to get tweets using Twitter API like this:

https://api.twitter.com/1.1/statuses/user_timeline/user_timeline.json?screen_name=username&count=2

But only when I go to that page, it returns the following:

{“errors”:[{“code”:215,”message”:”Bad Authentication data.”}]}

I haven’t found something additional or special which I should have added to the request on their documentation here https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html

Is anyone investigated it earlier? I’d be very pleased if you shared how did you do that.

3

Answers


  1. Chosen as BEST ANSWER

    I had to download their php ini file, which sends a request to the twitter domain and approves my website.


  2. Twitter’s API does not allow access without authentication via OAuth!
    Unauthenticated access is discontinued permanently.

    Check this out: https://developer.twitter.com/en/docs/basics/authentication/guides/authorizing-a-request

    Another guide that worked for me:
    https://tomelliott.com/php/authenticating-twitter-feed-timeline-oauth

    Login or Signup to reply.
  3. You need to go on the Twitter developers page and set up an App. You will not use it as an app, you only need the access keys. Then your code should begin like this: (I am using tweepy)

    import tweepy 
    consumer_key = 'XXXXXXXXXXXXXXXXXXXXXXXX'
    consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'
    access_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    access_token_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
    
    
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    
    api = tweepy.API(auth)
    
    myTweets = api.user_timeline("your_user_name/id")
    print(myTweets)
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search