Twitter Stream API, Parameter follow has unparseable items - python

Recently I'm doing a small project on twitter, and I want to get tweets from some specific users.
So I use Streaming API, pycurl and python.
The API Reference says the follow parameter is:
A comma separated list of user IDs, indicating the users to return
statuses for in the stream. See the follow parameter documentation for
more information.
And I tried this
c.setopt(c.POSTFIELDS, 'follow=slaindev')
but the return message is not the tweets that slaindev posted, but an error
Parameter follow has unparseable items slaindev
So do I misunderstand the meaning of user ID? I think it is the one we use to mention someone( I mean I use #slaindev to mention this guy).
When I try track parameter, it works fine.

Your assumption regarding user_id is incorrect. See this, for example. You are talking about screen_name.

Related

How to remove my own instagram followers with Python?

I want to remove my own instagram followers without blocking them, using python.
I have seen many, many, many, many instagram python libraries online that allow you to stop or start following a person, but that is not what I'm looking for; I don't want to remove who I am following or start following someone, I want to remove people who are following me.
I looked into the official documentation of Instagram's HTTP API trying to make my own solution, but I couldn't find the documentation of this action under any endpoint ( I assume it should be under /friends/ ).
I vaguely remember some library that used to do this, but I cannot find it. Does anyone know of a good way to achieve this, preferably via passing an inclusion/exclusion list for the followers I want to have as a result?
I found a solution in an old library that does something similar. You can't directly remove followers through most tools, but if you block and then unblock a user, the effect you want is achieved. Example code:
# https://instagram-private-api.readthedocs.io/en/latest/_modules/instagram_private_api/endpoints/friendships.html
import instagramPrivateApi
# ...
# Implement a Client class that inherits FriendshipMixin
api = new Client()
api.friendships_block(uid)
api.friendships_unblock(uid)
Here is the API endPoint for removing a follower https://www.instagram.com/web/friendships/{user_id}/remove_follower/
You can do a post request on this URL with appropriate headers and that can do the job.

How to get tweets in real time from a user's timeline using Tweepy

I'm trying to pull tweets from a user's timeline in real-time. I then want to do some analysis on those tweets. Having read the docs it looks like I will need to use tweepy.Stream for this use case. I've done the following:
stream.filter(follow='25073877')
But Twitter's filter API states the following:
Tweets created by the user.
Tweets which are retweeted by the user.
Replies to any Tweet created by the user.
Retweets of any Tweet created by the user.
Manual replies, created without pressing a reply
button (e.g. “#twitterapi I agree”).
It seems that this will return a huge volume of tweets that aren't relevant to my use case. Do I have to use this approach and then filter by screen name to get only tweets by the real user? This doesn't seem right at all.
The alternative seems to be the api.user_timeline class but that isn't a streaming API. Do I therefore use this API and hit it every second? I can't seem to find suitable examples of how best to accomplish my use case.
Yes, you'll need to filter either by screen_name or maybe you can check if it's a retweet or not.
I wouldn't recommend the second approach since you'll be getting an even bigger amount of tweets since you'll have to filter out the tweets you already received in previous requests plus you may hit the API querying limits if you don't time ti properly.
That's the signature of the filter function:
def filter(self, follow=None, track=None, is_async=False, locations=None,
stall_warnings=False, languages=None, encoding='utf8', filter_level=None)
Which maps to this Twitter API request.
And here the explanation of the parameters.

Filter tweets in python depending on possibly_sensitive value

I use a twitter bot and try hard to filter out tweets from my retweets that share inappropriate content.
Thus I want to filter all tweets out of my retweets that have "possibly_sensitive:true".
The bot is in python and I use the stream api method, have already imported tweepy and twystream.
the first approach i tried was to
elif jsonData['possibly_sensitive']
within a several steps query to filter out things i dont want to retweet. It wont even work a single time, basically the output hasnt changed at all.
the second approach was to enhance the track command for the stream.filter alike
keyword = "#hashtag filter:possibly_sensitive"
or tried this too:
keyword = "#hashtag possibly_sensitive:false"
as nothing works and I cannot really find other answers that helped me so far I am this desperated and joined stackoverflow.
Pls help me! Thanks
In the search API, try -filter:safe

How do you get the url from Submission object in PRAW?

I'm using PRAW to create a Reddit bot that submits something once a day. After submitting I want to save the url of the submission and write it to a text file.
url = r.submit(subreddit, submission_title, text=submission_text)
The above returns a Submission object, but I want the actual url. Is there a way to get the url from a Submission object, or do I need to do something else to get the url?
submission.shortlink (previously .short_link) is what you're looking for, if submission.permalink wasn't good enough.
reddit = praw.Reddit("Amos")
submission = reddit.get_submission(submission_id="XYZ")
print submission.permalink
>>> www.reddit.com/r/subreddit/comments/XYZ
I see that #TankorSmash has answered your question already, though I thought I might add some fundamental knowledge for future references:
If you use "dir(object)," you'll be able to see both attributes and methods that pertain to the Reddit API (which you may use to test and see all properties that effect the given object being tested). You can ignore everything that starts with an underscore (most likely).
An example would be:
submissionURL = submission.url
Or you can go straight to source where PRAW is getting its data. The variable names are not set by PRAW, they come from this JSON (linked above).

How can I get only responses tweets?

I need to retrieve specific data from twitter.
I'd like to get all the responses tweets received by a specific user (which is not the authenticating user of the program). Is there a way to achieve this? Right now I'm thinking about using the search function and see if the 'in_reply_to_user_id_str' matches the id of the user I want.
But this means that I need to filter a lot of data to find the one I want
Edit: I'm using the Python-Twitter-Tools
If it is the authenticating user, you can directly get the response tweets using the 'mentions timeline'. As the user is not the authenticating user, you have two options here.
Streaming API
Use the filter endpoint along with the 'follow' parameter. Pass the required 'user_id' to the follow paramenter and it will return the followings. You will have to check the 'in_reply_to_user_id_str' in order to isolate the replies(responses).
Tweets created by the user.
Tweets which are retweeted by the user.
Replies to any Tweet created by the user.
Retweets of any Tweet created by the user.
Manual replies, created without pressing a reply button.
Python-Twitter-Tools supports Streaming API. Streaming API is realtime and better than Search API considering the completeness.
Search API
Every response tweet contains the "#username" tag. You can searching using "#username" tag and then filter the tweets using 'in_reply_to_user_id_str' as you have mentioned.
Considering the two options, Streaming API will help you to get what you need easily and reliably.

Categories