Gegevens verzamelen via de Twitter API

Socialmediagegevens analyseren in Python

Alex Hanna

Computational Social Scientist

Twitter API

  • API: Application Programming Interface
    • Manier om gegevens te benaderen
  • Twitter API's
    • Search API
    • Ads API
    • Streaming API
Socialmediagegevens analyseren in Python

Streaming API

  • Streaming API
    • Tweets in real time
  • Filter-endpoint
    • Trefwoorden
    • Gebruikers-ID's
    • Locaties
  • Sample-endpoint
    • Willekeurige steekproef
Socialmediagegevens analyseren in Python

Data verzamelen met tweepy

  • tweepy
    • Python-pakket voor toegang tot de Streaming API
Socialmediagegevens analyseren in Python

SListener

from tweepy import Stream
import time

class SListener(Stream):
    def __init__(self, api = None):
        self.output  = open('tweets_%s.json' %
            time.strftime('%Y%m%d-%H%M%S'), 'w')
        self.api = api or API()
    ...
Socialmediagegevens analyseren in Python

tweepy-authenticatie

from tweepy import OAuthHandler
from tweepy import API 

auth = OAuthHandler(consumer_key, consumer_secret)

auth.set_access_token(access_token, access_token_secret)
api = API(auth)
Socialmediagegevens analyseren in Python

Gegevens verzamelen met tweepy

from tweepy import Stream

listen = SListener(api)

stream = Stream(auth, listen)
stream.sample()
Socialmediagegevens analyseren in Python

Laten we oefenen!

Socialmediagegevens analyseren in Python

Preparing Video For Download...