Understanding twitter streaming api response - twitter

I am not a very avid user and hence having a hard time figuring out what each field means in twitter api response. Going thru documentation has only resulted in me going in circles.
What I am trying to do is analyzing how things go viral. So, what I did was grabbed data from twitter streaming api with hope of analyzing the response but I am totally confused.
So a sample json response is :
{"created_at":"Thu Mar 14 18:19:12 +0000 2013","id":312266679390457857,"id_str":"312266679390457857","text":"The first four winners of our March Madness Giveaway (4x ADATA Technology (USA) 16GB DashDrives) are:\n\nAaron... http:\/\/t.co\/ikPbfRZQdq","source":"\u003ca href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\"\u003eFacebook\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":179622147,"id_str":"179622147","name":"Levetron","screen_name":"Levetron","location":"Los Angeles","url":"http:\/\/www.aziocorp.com","description":"Official Twitter for Levetron by AZiO. Here for customer questions, gaming tips & tricks, sharing cool ideas, product launch releases, reviews and more!","protected":false,"followers_count":1042,"friends_count":25,"listed_count":4,"created_at":"Tue Aug 17 18:56:29 +0000 2010","favourites_count":5,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":707,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"131516","profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme14\/bg.gif","profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme14\/bg.gif","profile_background_tile":true,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/3223061028\/999ac6efc782d85983cbcf7f2deab7c1_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/3223061028\/999ac6efc782d85983cbcf7f2deab7c1_normal.png","profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/179622147\/1360294489","profile_link_color":"009999","profile_sidebar_border_color":"EEEEEE","profile_sidebar_fill_color":"EFEFEF","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"entities":{"hashtags":[],"urls":[{"url":"http:\/\/t.co\/ikPbfRZQdq","expanded_url":"http:\/\/fb.me\/M6YPCk9W","display_url":"fb.me\/M6YPCk9W","indices":[112,134]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"medium"}
1)My guess is if this tweet is a result of a retweet then "retweeted" should be true.
But how do i figure out from which user it was retweeted?
2) Is "id" user id or tweet id?
Basically, if lets say I want to analyze how (say) Gangham style went viral.. who retweeted/followed that particular tweet, how should i do this?
Also, has twitter recently changed its api. I am using python for this but looks to me that all of those api's examples are not working
For example: https://github.com/tweepy/tweepy
Any suggestions.
Thanks

Please see the Twitter API documentation relating to tweets. It describes all parameters returned in the Twitter JSON response.
That tweet was not retweeted because retweeted is set to false and retweeted_count is 0.
From the documentation:
id = The integer representation of the unique identifier for this
Tweet.
Retweets can be distinguished from typical Tweets by the existence of
a retweeted_status attribute. This attribute contains a representation
of the original Tweet that was retweeted.
Also, here is a list of supported twitter libraries. There are several other libraries other than tweepy listed that might work for you.

Related

How to get the old timeline or tweet?

i'm University students of South korea
I'm developing analysis application using bigdata of twitter with my advisor professor. So i'm gathering tweets contains specific keyword(relevant word of crime) at period. I use 'streaming api' and 'search api' now. I have seen that using search api and streaming api result is return tweets of only one week.
I should be get the old data that have keyword of crime and since 2006 until 2016
do you have any idea?
Sadly you can't get tweets from that time range.
From the documentation:
The Search API is not complete index of all Tweets, but instead an index of recent Tweets. At the moment that index includes between 6-9 days of Tweets.
So, you can only get recent tweets from the search API. Be careful too with the data beacuse it's about relevance not completeness, from the same documentation:
Before getting involved, it’s important to know that the Search API is focused on relevance and not completeness. This means that some Tweets and users may be missing from search results. If you want to match for completeness you should consider using a Streaming API instead.
If you really need older tweets you will have to get them from other sources like Gnip. Otherwise you will have to approach differently your problem.
If you have the names (or id's) of all the users that you want to get info you could get the timelines from each user getting up to 3200 tweets.

How should I get all the tweets of an specific hashtag?

I'm trying to develop some code in order to get all the tweets that were generated with certain hashtags, then parse them and finally analyse them. I believe I've already thought and solve the last two parts of this but I'm having some trouble with the first one. I've already read the Twitter Search API documentation but I haven't realised yet how to do this. Can anyone help me?
If you want to retrieve the tweets sent recently, you should use the search/tweets endpoint of twitter' REST API, and mention the hashtag inside q parameter
In case you want to listen to tweets containing the hashtag and receive them in real time, then twitter's streaming API is what you should use (statuses/filter endPoint).
Have a look at the documentation on twitter's website, there's also plenty of information on how to do this all around the web.

How do I know if a specific twitter user is online or not?

How do I know if a specific twitter user is currently online by writing programs? Is there any API or data field in the web page showing this information? Both browsing Twitter webpage and using Twitter app are considered "online".
Although this information is not readily available, you can do a work around. Make use of Twitter's Streaming API: https://dev.twitter.com/docs/streaming-apis/streams/public (have a read through this document).
You'll most likely be using the POST Statuses/filter functionality (read the doc here: https://dev.twitter.com/docs/api/1/post/statuses/filter ), which will give you a JSON object with tweets based on your filters.
Make use of the parameters you'll need to specify in the URL to filter the stream (have a look through this document to learn more about it: https://dev.twitter.com/docs/streaming-apis/parameters ), in your case it'll be the follow parameter. You basically specify the twitter ID of the user you want to follow. Here's a sample JSON result of the streaming API in action https://stream.twitter.com/1/statuses/filter.json?follow=25365536 - this one in particular is following Kim Kardashian. Keep in mind that this will give you:
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.
So in order to just stream the tweets of your desired user, you'll have to use a programming language of your choice to parse through the JSON object to find the user that actually sent the tweet (this is a little tricky, you'll have to look through the properties of the JSON object to figure it out). Once you narrow the streaming tweets to just the ones from the user though, you can then have an alert on when new tweets by this user stream and that will tell you if the user is online/using twitter at the moment.
It's not clear what you mean by "online" (browsing twitter.com? Using a Twitter app?), but in any case Twitter doesn't provide such information, thankfully.
I'm afraid such information is limited by Twitter and is not available. However you can put your question on https://dev.twitter.com/discussions and ask its developers. Good Luck
you need get user state first
then filter if around current time
then get ids
they are online
use twitter developer api
I do it for my website

How can I obtain a sampling of all tweets from a specific time period?

I want to gather samplings of all tweets from the past year. Being able to request tweets from a specific date would be great, but I'll take what I can get.
I do not want to find tweets by a specific user or containing a specific term, just a sampling of all tweets. The Twitter search API claims that a query term is optional, but if I try an empty query like
http://search.twitter.com/search.atom
as opposed to giving a search term,
http://search.twitter.com/search.atom?q=twitter
the response is
<hash>
<error>
You must enter a query.
</error>
</hash>
If the API really doesn't provide any functionality for this type of query, how can I hack around it? Are tweet ids roughly sequential by date and can I somehow use this info to grab bunches of tweets centered around an id of a tweet whose date I know?
You are referencing the obsolete documentation. If you read the current version you will find that a query is required.
You should also know that the Search API only provides results going back about two weeks. You might be able to find historical data from sites like infochimps.
Not useful for historical data, but in case someone stumbles across this question looking for a sampling of all current tweets, you want the streaming API. (This is my first foray into Twitter and I hadn't noticed it. I only saw the public timeline method in the normal API.)

Does the Twitter API allow filtering by username AND hashtag?

Can I get all the tweets of a particular user, in which a particular hashtag is used?
I could just get the past 100 tweets then filter them on my end, but it would be much more convenient if Twitter could do the filtering on their end.
Is this possible?
Twitter's Advanced Search lets you construct the query you desire. Unfortunately, search results only seem to be for tweets posted within the past 24 hours or so right now; might just be a temporary limitation, not sure.
In any case, your request URL might look something like this (note the JSON and Atom types):
http://search.twitter.com/search?q=%23HASHTAG+from:USERNAME
http://search.twitter.com/search.json?q=%23HASHTAG+from:USERNAME
http://search.twitter.com/search.atom?q=%23HASHTAG+from:USERNAME
But with the current timeframe limitation, it's not very practical.
I am reading the twitter documentation and they say right now it will include only 6-9 days of tweets. Link https://dev.twitter.com/docs/using-search
To do this search against v1.1 of Twitter's API (which requires OAuth), you'd issue a GET request to the a URL structured like:
https://api.twitter.com/1.1/search/tweets.json?q=from:whitehouse+#sotu
See their Search API's "How to build a query" section. You'll be constrained to tweets over the last 7 days, though.

Resources