Python Twitter streaming API - followed users only - python

I'm attempting to get the statuses of followed users only using the Python Twitter library. It works fine for the 'everyone' stream:
from twitter.stream import TwitterStream
from twitter.oauth import OAuth
from twitter.util import printNicely
stream = TwitterStream(
auth=OAuth(
acc_key, acc_secret,
con_key, con_secret),
domain="userstream.twitter.com",
api_version='1',
secure=True)
print stream.statuses.sample()
tweet_iter = stream.statuses.sample()
for tweet in tweet_iter:
if tweet.get('text'):
printNicely(tweet['text'])
But I want to restrict the output to users I follow only. As far as I can tell from the docs, sample() gives me everything, but I can't tell whether there's a filter() method. Should I be using a different library? I've been using Tweepy for non-streaming Twitter tasks.

Actually, twython doesn't support support the userstream live stream. See here. There doesn't seem to be much activity in its user group, either.

I recommend twython for a Python Twitter library. It is regularly maintained, a useful property considering how often Twitter changes its API.
EDIT: See tweetstream for a simple streaming API implementation which as filtering capabilities.

Related

Access tweet annotations via tweepy

I'm using the python library tweepy in order to extract data from the twitter api v2.
The api also possesses the option to provide tweet annotations, which are basically categorization of certain elements used in the tweet. (The endpoint and documentation of this is available at: https://developer.twitter.com/en/docs/twitter-api/annotations/overview).
My question would be if there is a way to call this endpoint via tweepy? Or is there another way to access the automatic categorization of words using tweepy?
From the tweepy documentations:
tweepy.Tweet.context_annotations
should give you the infos you want.

Python code to connect to twitter search API

I'm new to Python and am very confused on how to begin this assignment:
Write Python code to connect to Twitter search API at:
https://api.twitter.com/1.1/search/tweets.json
with at least the following parameters:
q for a search topic of your interest;
count to 100 for 100 records
to retrieve twitter data and assign the data to a variable.
I already created the app to access Twitter's API. Thanks.
I had this same issue. According to Twitter, you must register an account to even use basic search features of public tweets and there is no way around it. I followed the guide for the complete setup here and can confirm it works
Edit: the article is for php, but changing it to python shouldn’t be very difficult. It has all the methods outlined in the article
Just as a hint, you might want to use tweepy for this. They have very good documentation and its much easier than trying to reinvent the wheel.

Twitter data mining for a specific user (python)

I want to setup a bot, which will read tweets from a twitter user and store. I can find several examples on search for particular key words, post ID etc.
Can any one recommend which api call is required for monitoring one particular user?
use tweepy for data mining from twitter https://github.com/tweepy/tweepy
The Twitter API call you would use is statuses/user_timeline. The documentation is here.
Some python examples to get you started with using Twitter are here.

How to tweet from GAE

I want to be able to Tweet from my app running on GAE.
Please suggest some Python library or HTTP API for the purpose.
About python-twitter: I think you can use this lib it seems to be compatible with GAE: http://code.google.com/p/python-twitter/source/browse/twitter.py
Also:
Twitter has a very great REST API https://dev.twitter.com/docs/api, You can also to simply use urlfetch and simplejson from appengine.
For authentication Twitter uses OAuth and recommend to understand how it work:
Twitter supports a few authentication methods and with a range of
OAuth authentication styles you may be wondering which method you
should be using. When choosing which authentication method to use you
should understand the way that method will affect your users
experience and the way you write your application.
Twitter share a very great how to https://dev.twitter.com/docs/auth/oauth
You can also see the part of code: http://code.google.com/p/jaikuengine/source/browse/trunk/oauth_client.py from jaikuengine.
This project worked for me: https://github.com/tav/tweetapp/blob/master/standalone/twitter_oauth_handler.py
It's only one file so it's easy to get it started and uses OAuth for authentication with twitter.
I have used twython in the past. I can't remember what made me select it over other libraries but I was using it on GAE and it is kept up-to-date.
You might find the Tweet Engine project of interest. It demonstrates quite simply how to use the Twitter REST API from App Engine.

How to tweet from Django?

I want to create a manage.py command that takes an object from a queryset and posts it on my Twitter. I was going to use the curl method as described in here.
But Twitter has since disabled basic authentication. I don't want to install an overkill library like Tweepy that lets people authenticate to my site with oAuth, I just simply want to tweet. On a single account.
from twitter api page:
For applications with single-user use cases, we now offer the ability to issue an access token for your own account (and your own applications). You can generate these keys from your application details pages. Find out more about using a single access token.
go to https://dev.twitter.com/apps to get your keys
from there on out, python-twitter will be happy to parse these keys for you with
api = twitter.Api(consumer_key='consumer_key', consumer_secret='consumer_secret',
access_token_key='access_token', access_token_secret='access_token_secret')

Categories