skip to Main Content

I want to use twitter api for poll votes using tweepy is there any methods to implement this?

I tried doing api.update_status("poll_1"[1112227775552223333]) but its not working.

2

Answers


  1. No. The poll API is private and is not available to anyone apart from Twitter’s own apps.

    There are no plans to open this to the public – https://twittercommunity.com/t/poll-support/78235

    Login or Signup to reply.
  2. The other answer is incorrect. There is a way, it’s just the JSON data you get back is quite unwieldy (I have plans to build a tweepy addon to make this easier). The way to get it with Python 3.x is through requests. Don’t worry though, it’s only a line or so of code. As you can see in this link, we can indeed get back twitter poll data. Here’s a code snippet:

    import requests, json, OAuth1
    
    # provided by a Twitter dev account
    auth = OAuth1(my_key, my_secret_key, my_access_token, my_secret_access_token) 
    
    tweet_ids_string = "12345678,123456790,09886654333"
    
    # for more expansions see the link above
    data_url = f'https://api.twitter.com/2/tweets?ids={tweet_ids_string}&expansions=attachments.poll_ids&poll.fields=duration_minutes,end_datetime,options,voting_status' 
    
                               
    response = requests.get(get_data_url, auth=auth)
    response_json = response.json() # then you can get all sorts of data from here
    

    Beware though, the Twitter polls API isn’t lightning fast, so there might be several seconds of a delay between a poll getting voted on and the request JSON changing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search