Twitter API के ज़रिए डेटा इकट्ठा करना

Python में सोशल मीडिया डेटा का विश्लेषण

Alex Hanna

Computational Social Scientist

Twitter API

  • API: Application Programming Interface
    • डेटा एक्सेस करने का तरीका
  • Twitter APIs
    • Search API
    • Ads API
    • Streaming API
Python में सोशल मीडिया डेटा का विश्लेषण

Streaming API

  • Streaming API
    • रियल-टाइम ट्वीट्स
  • Filter endpoint
    • कीवर्ड्स
    • यूज़र IDs
    • लोकेशन्स
  • Sample endpoint
    • रैंडम सैंपल
Python में सोशल मीडिया डेटा का विश्लेषण

डेटा इकट्ठा करने के लिए tweepy का उपयोग

  • tweepy
    • Streaming API एक्सेस करने के लिए Python पैकेज
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()
    ...
Python में सोशल मीडिया डेटा का विश्लेषण

tweepy authentication

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)
Python में सोशल मीडिया डेटा का विश्लेषण

tweepy से डेटा इकट्ठा करना

from tweepy import Stream

listen = SListener(api)

stream = Stream(auth, listen)
stream.sample()
Python में सोशल मीडिया डेटा का विश्लेषण

अभ्यास करते हैं!

Python में सोशल मीडिया डेटा का विश्लेषण

Preparing Video For Download...