Tweeter

Asked

Viewed 397 times

0

I am using the API provided by Tweeter next to python to fetch certain tweets.

The problem is that I wish view the tweets received by the person and not the tweets sent by them however, I am not succeeding, I just view the tweets of the page in question. follows 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)

1 answer

2


You’re getting the tweets sent by the person because that’s what the method .user_timeline() ago...

On Tweeter there is no sending tweets for 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 need to be a Tweeter user, because tweets are public, so you can use a AppAuthHandler instead of OAuthHandler if you want, it’s much faster.

  • Perfect! Thank you !!

  • Can you tell me how I can format these tweets? Whether they’re for a Facebook or something? without all specifications, just the tweet itself?

  • 1

    api.search() returns objects of the type SearchResult - to get the text of the tweet just use the attribute text, for example: print(t.text)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.