I'm thinking up a new website idea which would allow a visitor to view on a map where certain things have happened. I want to use Twitter, with the idea that someone tweets using a specific hashtag. I want to capture that tweet using the API and find the location of where the tweet came from. Is this possible?
It is possible. However there are lots of tweets (a majority in reality) which do not get any location and it is impossible to get it for these ones. To be located, a user must enable location in its account parameters and give its location with the tweet while posting it but a majority of tweeps do not do that.
For retrieving tweets location, you just have to download the tweet with the corresponding Twitter API endpoint (GET statuses/show/:id). Once you get the tweet, search its "coordinates" field. This field has got a subfield also called "coordinates". This subfield is a list with two numbers : [longitude, latitude]. For further information, refer to the Twitter Developers documentation about tweets and coordinates.
Related
I have a website which allows the user to tweet using a specific hashtag, would their be anyway to actually find out if the user has really tweeted.
I was thinking of looking at the timestamps and just working out the difference between right now and when the last tweet was made but that's not really professional.
I know Facebook allows you to do this quite easily but I'm struggling to figure out the best solution.
any ideas?
Regards
Retrieve the tweets of the user in question
Scan the text of each tweet, looking for your hashtag.
If you know when they visited your website, compare the time of the visit to the time of the tweet.
If you need to ensure the users tweets, then tweet for the user by requesting authorization and then tweeting via the API. This will still not stop the users from deleting the tweet.
If you plan any reward scheme, you won't be able to force users to keep the tweet (and probably the twitter API ToS forbid such things).
You want to use the Twitter STREAM API. One of the public stream is the Filter Stream.
This stream give the possibility to specify keywords/hashtags that you want to follow in live.
You can simply track the hashtag that you want and then you will receive in live all the tweets posted with your hashtag.
You can then simply check the json property user and compare the id/screen_name to the user you want to identify.
What would be the easiest way to extract the Lat and Long fields of a 'check-in' location being tweeted? When viewing tweets through a client and "expanding" them the location is shown even though the tweet does not always contain the geoLocation properties. I would like to achieve the same result (Is a Foursquare API account needed for that?)
I am using Twitter4j by the way.
Thanks for the help,
Boris
If the information is not in the geoLocation property, you will need to call the foursquare API (https://developer.foursquare.com) to retrieve the lat/lng for the venue the user checked in to. You may want to look at similar questions that have been asked in the past for more details, like: How can I get the position (lat, lon) of a foursquare checkin posted on twitter?
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
I am not sure how it is done, therefore my questions below:
I would like to ask folks on Twitter for a suggestion on a particular topic. Can I tell them to use certain hashtag and have all comments with that hashtag posted on my site?
Do I just pick a hashtag or does it need to be created somehow?
Can I have users on my site rate those suggestions? In that case, would I need to somehow grab twitter message and store locally?
Just trying to understand the process in order to implement it.
Hashtags don't have to be created - just use it in tweet.
In order to get all tweets with particular hashtag, use search API: https://dev.twitter.com/docs/api/1/get/search and search for this hashtag. You should save all relevant tweets (twitter search is not reliable on old tweets).
I'm using the Twitter search api to search for a keyword so I can grab all the tweets containing that keyword. I also need to find the location of these tweets. Is this possible? I've looked through the JSON and the 'Geo' property is always null - i'd be happy to just use the location that the user has filled out in their profile but I can't see that this is available through the search api.
I've seen lots of apps that allow you to find tweets nearby based on your location but I want to do something different. find tweets by keyword and then find their location.
Is this possible?
Apologies, just found a solution.
The REST api allows me to query based on a search string:
http://search.twitter.com/search.json?&q=twitter
and this returns some json including the user id and then from there I can query again using this:
http://api.twitter.com/1/users/show.xml?user_id=1401881
which returns me user info including a location.