How to get users followed/unfollowed time in python

streaming
python
tweepy
api
sitestreams

#1

How can I make API call to get Event data from twitter site stream data. I want to capture the time which one person followed/unfollowed another person.
{
“event”:“EVENT_NAME”,
“created_at”: “Sat Sep 4 16:10:54 +0000 2010”,
“target”: TARGET_USER,
“source”: SOURCE_USER,
“target_object”: TARGET_OBJECT
}


#2

Moving this to the streaming API category.


#3

Hello, Bello_bichi

As you can see in Streaming With Tweepy - Tweepy Documentation, you can get that data by defining your own StreamListener class like this:

class MyStreamListener(tweepy.StreamListener):
    def on_event(self, event):
        if event.event == 'follow':
            time = event.created_at
            source_user = event.source
            target_user = target_user
            some_process(time, source_user, target_user)

and then, create StreamListener object and stream:

stream_listener = MyStreamListener()
stream = tweepy.Stream(auth=api.auth, listener=stream_listner)

When you call sitestream() method like below, Tweepy would handle your sitestream and call on_event() on demand.

stream.sitestream(follow=[31415926,5358979])

#5

Thank shuuji3 for the help. I got an error on this line "stream.sitestream(follow=[31415926,5358979]) "
AttributeError: ‘Stream’ object has no attribute ‘sitestream’ , I try to fix it but still I could not do it.


#6

Umm… tweepy.Stream should have sitestream() method.

To know more details, can you show the tweepy’s version, by print(tweepy.__version__), and the code you ran?


#7

thank you the reply,
the version is 2.1 , the code still did not ran.


#8

Hi, Bello_Bichi

The version 2.1 was released 2.5 years ago and the latest version is 3.5. Twitter API sometimes changes, and the old version doesn’t come to work. So you’d better upgrade Tweepy library to the latest version.


#9

Thank you for all the effort. I have upgrade my tweepy to 3.5, and the program ran no error but no any output. I use print(event.created_at) but it print nothing. how can I print the time?

def on_event(self, event):
    #def on_data(self, data):
         if event.event == 'follow':
            time = event.created_at
            source_user = event.source
            target_user = target_user
            some_process(time, sousrce_user, target_user)
            print(event.created_at)

#10

Thank you for all the effort. I have upgrade my tweepy to 3.5, and the
program ran no error but no any output. I use print(event.created_at)
but it print nothing. how can I print the time? Thank you very much

def on_event(self, event):
    #def on_data(self, data):
         if event.event == 'follow':
            time = event.created_at
            source_user = event.source
            target_user = target_user
            some_process(time, sousrce_user, target_user)
            print(event.created_at)

#11

hi Shuuji3 could you please rely me