Is there an easy way to get the number of followers an account has without having to loop through cursors? I'm looking for a simple function call which will return to me just the number of followers the use with a given Twitter ID has.
Just looking for the physical number not access to anything else
What I ended up doing was .show_user(user_id=twitter_id) which returns (among other things) the followers count via ['followers_count']
You can use get users/lookup endopoint to query up to 100 of screen names or user ids, followers_count is included as well.
In twython it would be lookup_user api function.
Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the user_id and/or screen_name parameters.
Related
I am working on a project using Tweepy where I need to first grab all followers for a particular Twitter user, and then do the same for all of those followers' followers. I would like to store the latter part in a dictionary where the keys are the first set of followers, and the values are a list of their followers.
Here is my code:
followers_dict = {}
for h in myHandleList:
try:
c = tweepy.Cursor(api.followers_ids, id = h)
for page in c.pages():
followers_dict[h] = page
except tweepy.TweepError:
pass
This code works well for users with under 5000 followers. However, for users with more than 5000 followers, when I run the same code, the code splits their followers into separate lists of no more than 5000 values, and then only adds the second list as values in the dictionary.
For example, one user has 5,400 followers, so when I download their followers, it is formatted as two lists of 5000 and 400. When I use my loop to add their followers to a dictionary, it only adds the second list of 400. I would like to add all 5,400 as values in the dictionary.
I am a noob when it comes to Python, and as someone pointed out in the comments, this is surely an issue with my code - Any suggestions for how to fix this?
Thanks in advance!
I am trying to fetch a subscription list according to the Subscriptions: list documentation. I want to get all my subscribers so I am using mySubscribers=True in the parameter list in a loop after my first request.
while "nextPageToken" in my_dict:
next_page_token = my_dict["nextPageToken"]
my_dict = subscriptions_list_by_channel_id(client,
part='snippet,contentDetails',
mySubscribers=True,
maxResults=50,
pageToken=next_page_token
)
for item in my_dict["items"]:
file.write("{}\n".format(item["snippet"]["channelId"]))
The problem is at page 20 my loop breaks, i.e. I don't recieve a nextPageToken key in the response capping my data to 1000 total subscribers fetched. But I have more than 1000 subs. The documentation states that myRecentSubscribers has a limit at 1000 but that mySubscribers does not.
Can not really find much help with this anywhere. Any light on my situation?
I chose to list channels instead of listing subscriptions, passing the same argument mySubscribers. The documentations says it's deprecated and gives them back in a weird order with duplicates but it does not have a limit.
How would I limit the number of results in a twitter search?
This is what I thought would work...tweetSearchUser is user input in another line of code.
tso = TwitterSearchOrder() # create a TwitterSearchOrder object
tso.set_keywords(["tweetSearchUser"]) # let's define all words we would like to have a look for
tso.setcount(30)
tso.set_include_entities(False) # and don't give us all those entity information
Was looking at this reference
https://twittersearch.readthedocs.org/en/latest/advanced_usage_ts.html
tried this, seems like it should work but can't figure out the format to enter the date...
tso.set_until('2016-02-25')
You should use set_count as specified in the documentation.
The default value for count is 200, because it is the maximum of tweets returned by the Twitter API.
I am trying to 'trace back' from a given Soundcloud track resource object to the Soundcloud user resource object that created it. Given my understanding of the Soundcloud API this is what I have done.
1st: Retrieve a specific track
track = client.get('/tracks', title="White Lies (feat. Jenni Potts)",
limit=1)
This should return a collection of one track (by Odesza).
2nd: Gather info about tracks user from track resource
white_lies_perma = track[0].user["permalink"]
white_lies_uID = track[0].user["id"]
3rd: Get the user (hopefully) using the above filters
users = client.get('/users',
id=white_lies_uID,
permalink=white_lies_perma)
This should return 1 user, however the length of the resource collection is 50 (the API default). This is strange.
Printing the values:
for user in users:
print(user.id)
79582
2684450
3765692
9918957
12470953
etc...
This should just be a collection of length 1, containing a resource with id 18604897.
Furthermore, this code should reasonably return "Oklahoma City" twenty times over. However when run it gives me "Cape St Francis", "Augusta", "London U.K".
client = soundcloud.Client(client_id='xxxxx')
okcUsers = client.get('/users',city="Oklahoma City",limit=20)
for okcUser in okcUsers:
print okcUser.city
Is something wrong with Soundcloud's API?
Not sure how you implemented those filters in your 3rd call, but I think you should get the information you needed if you do
users = client.get('/users/%d' % white_lies_uID)
Since you do not need to do a search but just call the correct /users/ endpoint. To see which endpoints are available for a specific user go to https://developers.soundcloud.com/docs/api/reference#users and scroll down to below the list of fields a user contains. There you see a list of endpoints that can be called once you have a user id.
I am using tweepy library to pull informations about Twitter users. What I want is, given a list of Twitter ids, get the number of followers of each user that relates to the ids. The function looks like this.
infos = api.get_user(user_id=xxx)
return infos.followers_count
In the Twitter documentation, it says I can input a list of up to 100 user ids to get_user. Thing is, whatever I pass to that function other than a single id, I get the error
[{'message': 'Sorry, that page does not exist', 'code': 34}]
For example if I write:
infos = api.get_user(user_id=[user1,user2,user3])
I get the error. But if I write
infos = api.get_user(user_id=user1)
It works perfectly well. Did you encounter this problem before? Is the problem in Tweepy library? Should I use another library?
Thanks for your support
You need to use the function lookup_users for this, and the parameter is user_ids:
infos = api.lookup_users(user_ids=[user1,user2,user3])
https://github.com/tweepy/tweepy/blob/master/tweepy/api.py#L154