weird Twitter API behaviour - python

I know sure is it me or everyone, I have a following code
http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=barbara_volkwyn
http://api.twitter.com/1/statuses/user_timeline.xml?user_id=248623669
Apparently according to Twitter api, user with screen_name = "barbara_volkwyn" has the user id = 248623669, however, when I run the above API call I get totally different result, one thing that's even weirder is if I try to run the second API call, the users object contain in the returned result is not even the same user.
I wonder anyone has the same problem, feel free to give it a try.
Regards,
Andy.

your userID of barbara_volkwyn isn't valid. It should be: 264882189
You can fetch userID's trough the api or with https://tweeterid.com/

The user_ids reported by the Search API aren't the same as the user_ids used in the Twitter REST API -- unsure if that's where you found the user_id 248623669 or not though.
A timeline contains tweets which in turn contain embedded (but cached) user objects, usually reflecting the state of the user at the time the Tweet was published. Sometimes users change their screen_names, so a user by the name of #barbara_volkwyn might be user_id 1234 one day and user_id 5678 the next day, while the tweets that belonged to user_id 1234 will always belong to user_id 1234, regardless of the screen_name.
The user_id for #babara_volkwyn according to the REST API is 264882189. It's entirely possible that someone held the same screen name but a different user_id at another time. The only way to ever be certain about the identity of a Twitter user is to refer to them by their REST API user_id -- screen_names are transitory and can be modified by the end-user at any time.
As I mentioned, cached user objects used within statuses can become stale -- the most reliable source for up-to-date information about a single user account is the user/show API method. The most reliable source for up-to-date information on recent Tweets by an account is the statuses/user_timeline method.
The embedded objects work for most scenarios, but if you're looking for maximum accuracy, the distinct resources are best.
Thanks, Taylor.

Related

User ID's returned from Tweepy are huge numbers that don't link to any accounts

I have been downloading tonnes of tweets for the last few weeks. In order to reduce download time, I only saved tweet user ids not the user account. I need to pass them through a bot check but have now realised that 90% of the user ids are huge numbers (e.g. 1.25103113308656E+018) and cannot be used to search for the account.
Is there a way to convert these back to an account number?
Notes:
The tweet_id column is an equally huge, different number meaning they haven't been read into the wrong column.
When I raise them from the e notation into their raw number it still doesn't work.
I am limited by the week window of the twitter api so I must find a way of linking the data I have already got to individual accounts. This work is for a charitable cause and your help would be greatly appreciated.
The Tweepy API call returns a Response which contains the data in the _json field. You can parse the user key of the said json and extract the IDs and the screen name of the user and store it.
Then you can query the Tweepy api again as per their doc to get the user information.
Please make a note that when you store the ID field, you have to cast it to the String datatype.

tweepy get list of failed lookup_users

I'd like to check if a set of twitter users are exist or not. As I couldn't find any better method, I used api.lookup_users() but it returns nothing when a user name is not found. How can I get list of users that are failed to look up.
>>> api = tweepy.API(auth)
>>> user_ids = api.lookup_users(screen_names['hamid', 'python'])
>>> print user_ids
[19877641]
But I need the failed ones also something like: [19877641,None] or [19877641,""] etc.
That's more on Twitter's side than tweepy. If a user is not found using GET users/lookup nothing is returned. So tweepy is returning what is being received from the API.
From their docs:
There are a few things to note when using this method.
You must be following a protected user to be able to see their most recent status update. If you don’t follow a protected user their
status will be removed.
The order of user IDs or screen names may not match the order of users in the returned array.
If a requested user is unknown, suspended, or deleted, then that user will not be returned in the results list.
If none of your lookup criteria can be satisfied by returning a user object, a HTTP 404 will be thrown.
You are strongly encouraged to use a POST for larger requests.
A possible workaround is to send the users individually and if you get None then change your list accordingly. Unfortunately that can hinder you limit.

How to fetch tweets of a given user?

I'm trying to use the Twitter API in order to automatically fetch the last tweet of a given user, but I'm having trouble :/
I am using this library : https://code.google.com/p/python-twitter/
I installed it, everything seems working, but when I try to fetch the timeline of a user, I only get all my timeline :(
Here is my code:
import twitter
api = twitter.Api(consumer_key='***', consumer_secret='****', access_token_key='***', access_token_secret='****')
statuses = api.GetUserTimeline('#twitterapi')
print [s.text for s in statuses]
Is there something I missed ?
I believe you have to provide the userId rather than the screen_name in order for the GetUserTimeLine to work.
Also, although you might expect that this would return the equivalent of that user's home status page, it does not. Instead, it returns just the tweets from that user.
The twitter API documentation mentions another method - GetFriendsTimeline, but, despite being listed in the documentation, it doesn't seem to exist as far as I can tell.
You must explicitly enter screen_name= or user_id= otherwise the value defaults to the authenticated user.
Examples:
statuses = api.GetUserTimeline(screen_name='some_handle')
or
statuses = api.GetUserTimeline(user_id=22233344)

How to get google ID from email

I'm using google ID as the datastore id for my user objects.
Sometimes I want to find a user by email. The gmail address can appear with dots or without, capital letters and other variations. How can I retrieve the user id from the given email?
First of all you should store the email property always in lowercase since the case is not relevant. Now if you also want to take into the account the dot or the plus symbols and being able to query on them, you should then store in another (hidden) property the stripped out version of the email and execute your queries on this one.
Google+ seems to have an API for this
https://developers.google.com/+/api/latest/people/search

Comparing user's facebook/twitter friends to site's users in Python/Django

I'm wondering if someone could help guide the approach to this fairly common problem:
I'm building a simple site which a user connects their twitter account to sign up. I'd like to create an interface which shows them which of their twitter friends are already using the site.
So I can get a list the user's twitter friends, and a list of the site's users (which all have the twitter screen name as username, but I'm wondering the most efficient method to compare these lists and create a variable with the commonalities.
As an aside, given the Twitter API returns IDs, should I save the twitter user's ID (in addition to their username) when they create an account?
Thanks in advance!
Create Sets out of them, and use the intersection method:
intersection_set = set(list_a).intersection(list_b)
You should store the twitter user's ID because the username can change at any time, but the id will always be the same. You should be comparing the id's, not the usernames in the intersection_set that Ofri recommends.

Categories

Resources