skip to Main Content

I would like to write a script in Python to read a public Twitter profile. Specifically, I’d like to check for Tweets with images, and download those images (eventually, I’d like to add this as a cron job). I was looking into tweepy as a Twitter API wrapper. However, from what I understand, the Twitter API requires authentication even for actions that access public data – is that correct?

Since all I need is to access a single public user timeline, going through the rigmarole of authenticating (and then having those credentials sitting on my computer in I’m not sure how secure a form) seems a little overkill.

Are there other solutions out there (particularly Python-based) for reading public Twitter data?

2

Answers


  1. You can always create your own data scraper. BeautifulSoup is a popular one. For example something like this:

    from urllib.request import urlopen
    
    html = urlopen('https://twitter.com/Microsoft')
    soup = BeautifulSoup(html.read(),'html.parser');
    print(soup)
    
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.1//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile11.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta content="True" name="HandheldFriendly"/> ......................
    
    Login or Signup to reply.
  2. Yes, Twitter does require, authentication to access any public/private data of user. You need to create an app on Twitter to access the data. The app is required to keep a check on the number of requests, etc. made by a particular client, to prevent any abuse. This authentication is a general process followed by other API providers as well and this is the only recommended way.

    Another advantage of creating a Twitter App is that other users can give permissions to your app and then you can access their private data as well such as DM, etc.

    Another approach is web-scraping, but I would consider it as unethical as twitter is already providing it’s API. Also you would need to update your scraping script each time there is some front end change by the Twitter developers.

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