Twitter API check for NSFW content - twitter

In the Twitter Api is there anything in the response that tells if the Tweet has been flagged as NSFW or inappropriate? The response is quite big but I couldn't find anything in it that flags the Tweet as NSFW.

There is a possibly_sensitive flag in the Twitter API, tweet object.
possibly_sensitive Boolean Nullable. This field only surfaces when a
tweet contains a link. The meaning of the field doesn’t pertain to the
tweet content itself, but instead it is an indicator that the URL
contained in the tweet may contain content or media identified as
sensitive content.
Example:
"possibly_sensitive":true

Related

how to identify the url in tweet is images, video, article or tweet link?

I am collecting tweets. And want to segregate them as per image, videos and articles. Basically tweet segregation based on their media content
Is there any way or logic by which I can recognize that the url in tweet is reffering to some image or video or article ?
For media, you can check the Extended Entities Object. In the object, there is a key named "type" - if the tweet you're analyzing has some media, the value can be one of "photo", "video", "animated_gif".
For articles, you can check the plain Entities Object if the tweet doesn't contains any media when you checked the Extended Entities Object (since media in twitter is URLs too - meaning that if the tweet doesn't contain any media then the URLs contained in the tweet must be a link).
You can get HTML title and description of the link in the Entities Object API, but unfortunately Twitter Cards are not provided by Twitter API - if you need Twitter Card information you should parse the HTML <head> element and get the information yourself. For detais see the Twitter Cards documentation.

Twitter API returns Link to tweet while tweet has no link

I have a tweet in my timeline which has no link. When I retrieve my tweets via the twitter API it contains a link which refers to the tweet itself, e.g.:
"expanded_url": "https://twitter.com/i/web/status/<tweed-id>",
Is this intented behaivior?
I searched for this in the twitter API Docs but was not able to find anything.
If you check the Tweet JSON and it contains the field truncated: true then you need to use the tweet_mode=extended parameter to retrieve the complete Tweet object.

Can the time stamp of a Retweet be accessed?

I'm trying to use the Twitter API: GET statuses/retweets/:id
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-retweets-id
It doesn't seem like the API returns the time a Tweet was retweeted. It only shows when it was created. Is this true? And if so, is there any other way of being able to retrieve the retweet timestamp?
From Introduction to Tweet JSON:
If you are working with a Retweet object, then that object will contain two Tweet objects, complete with two User objects. The Tweet that was Retweeted is referred to as the 'original' Tweet and is displayed under the 'retweeted_status' key. If a Retweet gets Retweeted, the 'retweet_status' will still point to the original Tweet, meaning the intermediate Retweet is not included.
The top-level created_at attribute should be the time of the retweet that you're looking for. The original tweet is embedded inside the retweet object as the retweeted_status and it has its own (earlier) timestamp.

How to find all 'retweet with comments' for a particular Tweet using API?

I want to get all the 'retweets with comments' of a tweet.
Here are few things I noticed with twitter api
Retweets with comments are treated as tweets. The retweet count does not increase if you add a comment, also the twitter message is "XYZ quoted you instead retweeted you'
You clearly can't use this API endpoint https://dev.twitter.com/rest/reference/post/statuses/retweet/:id
Is there a way to find all the 'tweet/retweet with comment' if you can supply the original Tweet/Id?
So you're referring to Quoted Tweets (retweet with comments). There is no official method for that from the REST API yet, however, there are couple of ways to do it.
Since all quoted tweets contain the short url to the original one,
you can still use in_reply_to_status_id and filter by short url of the original tweet
Search for tweets that contain the field quoted_status_id this can be done either through REST or STREAMING API.
quoted_status_id: This field only surfaces when the Tweet is a quote Tweet. This field contains the integer value Tweet ID of the quoted Tweet.
This isn't easy to accomplish. Here's the brute-force API method to find Quote Tweets.
Take your tweet id, it'll be something like 750176081987014657.
GET search/tweets
Use the Twitter API and search for the tweet.
https://dev.twitter.com/rest/reference/get/search/tweets
The GET request will look something like this:
https://api.twitter.com/1.1/search/tweets.json?q=750176081987014657&count=100
The q "query" argument is the tweet id. I've set the result count argument to the maximum (100).
Authorization
Of course with the Twitter API there's a whole bunch of tricky Authorization header work you have to do as well in order to complete the GET request. That's documented elsewhere and is beyond the scope of this answer.
Results and Conclusion
When you have the JSON results of this GET request, focus on the statuses collection. For each tweet in the collection (otherwise known as a "status"), check if it contains a quoted_status_id field. If it does, and the field value matches your tweet id, the tweet is a quote tweet. If it does not, it is simply a retweet with no added comment. You will also have to deal with iterating through the pagination of results if there are more than 100. That's done by looking for a search_metadata.next_results field and retrieving the next GET query string from it, which will be provided for you.

Twitter API - Display all tweets with a certain hashtag?

How would I go about displaying tweets that contain a certain hashtag using the Twitter API? Thanks
I'd also like to know if there is a way to get all tweets from a certain hashtag in a separate file, also the ones that don't show up in your feed anymore. I suppose that's what the earlier question was about, too.
This answer was written in 2010. The API it uses has since been retired. It is kept for historical interest only.
Search for it.
Make sure include_entities is set to true to get hashtag results. See Tweet Entities
Returns 5 mixed results with Twitter.com user IDs plus entities for the term "blue angels":
GET http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&with_twitter_user_id=true&result_type=mixed
UPDATE for v1.1:
Rather than giving q="search_string" give it q="hashtag" in URL encoded form to return results with HASHTAG ONLY. So your query would become:
GET https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames
%23 is URL encoded form of #. Try the link out in your browser and it should work.
You can optimize the query by adding since_id and max_id parameters detailed here. Hope this helps !
Note: Search API is now a OAUTH authenticated call, so please include your access_tokens to the above call
Updated
Twitter Search doc link:
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html
The answer here worked better for me as it isolates the search on the hashtag, not just returning results that contain the search string. In the answer above you would still need to parse the JSON response to see if the entities.hashtags array is not empty.

Resources