Tweet Crawler

I am using the API provided by tweeter alongside python to fetch certain tweets.

The problem is that I want to view the tweets received by the person and not the tweets sent by them but I am not having success, I only view the tweets of the page in question. following code:

import tweepy
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener

access_token = "minhas credenciais da API para devs do TT"
access_secret="minhas credenciais da API para devs do TT"
consumer_key="minhas credenciais da API para devs do TT"
consumer_secret="minhas credenciais da API para devs do TT"


auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

api = tweepy.API(auth)

# The Twitter user who we want to get tweets from
name = "skyresponde"
# Number of tweets to pull
tweetCount = 5

# Calling the user_timeline function with our parameters
results = api.user_timeline(id=name, count=tweetCount)

# foreach through all tweets pulled
for tweet in results:
   # printing the text stored inside the tweet object
   print(tweet.text)
Author: HV Lopes, 2018-10-22

1 answers

You are getting the tweets sent by the person, because that is what the .user_timeline() method does...

In the tweeter there is no sending tweets to someone. What exists is mentions or direct message.

To find direct message, you can use:

for m in api.direct_messages():
    print(m)

To find the mentions, you need to locate with search:

for t in api.search(q='@skyresponde', count=100):
    print(t)

Remembering that to use the latter, you do not have to be a tweeter user, since the tweets are public, so you you can use a AppAuthHandler instead of OAuthHandler if you want, it's much faster.

 2
Author: nosklo, 2018-10-22 18:33:31