开发者

Twitter API: How to search only for geotagged tweets

How can I use Twitter Search API (or other) to get a list of tweets which have the "geo" param?

--EDIT--

By example: I wont get list of ge开发者_JAVA技巧otagged tweets, by #apple tag. Without location filter, worldwide.


Looks like the latest API supports that; simply use a large enough geo region for your query:

-180,-90,180,90

See more from the API link for filter and location


The streaming API allowed you to filter by a location and the search API allows you to search by geocode. You can find more information on these services on our developer resources site.

Streaming API: http://dev.twitter.com/pages/streaming_api

Example: Create a file called ‘locations’ that contains, excluding the quotation marks, the phrase: “locations=-122.75,36.8,-121.75,37.8,-74,40,-73,41” then execute:

curl -d @locations http://stream.twitter.com/1/statuses/filter.json -uAnyTwitterUser:Password.

You will receive all geo tagged tweets from the San Francisco and New York City area.

Search API: http://dev.twitter.com/doc/get/search

Example: http://search.twitter.com/search.json?geocode=37.781157,-122.398720,1mi


From the Twitter API Documentation, this should be the format of your search query:

 http://search.twitter.com/search.json?geocode=37.781157,-122.398720,1mi

Where 37.781157 is the latitude, -122.398720 is the longitude and 1mi is the radius to search within.


You can look for every tweet but save only the geotaged ones. I know it dont make a lot of sense, but works quite well.

if you call you search results, you can state

for result in results:
    if result.geo != None:
        print result.text.encode('utf-8', errors='ignore')  # or do anything you want with the tweets


Use -180,-90,180,90 to get any geotagged tweet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜