pythontwitterpython-twittertwitter-search

Getting tweets in twitter-python using using place id


I am trying to get the tweets which contain a particular search term and have been tweeted from Mumbai . I know the place id of Mumbai is: 7929cea6bd5b32bd . I am using python-twitter in python 2.7.9 and the following code:

    search_string="place:7929cea6bd5b32bd string"
    alltweets=[]
    new_tweets=api.GetSearch(search_string,count=100,result_type="recent")
    alltweets.extend(new_tweets)

I get a bunch of tweets as a result. However, when I find the location of user that has tweeted it using:

    p=api.GetUser(user_id=id)
    print p.location

The location turned out to be different in many cases(It is the location that we update in the profile) . I wanted to know, when we search for tweets with a particular string using "place:place_id", what location does twitter take? Is it where the user is while tweeting the tweet or the location that we provide in our profile?


Solution

  • When you use place: it is the location of a user when they posted the tweet. In your case the results will either be Mumbai or a more specific place inside Mumbai, such as a neighborhood.

    $ oksocial 'https://api.twitter.com/1.1/search/tweets.json?q=place%3A7929cea6bd5b32bd' | jq '.statuses[].place.full_name'
    "Mumbai, India"
    "Mumbai, India"
    "Mumbai, India"
    "Mumbai, India"
    "Mumbai, India"
    "Mumbai, India"
    

    San Francisco

    $ oksocial 'https://api.twitter.com/1.1/search/tweets.json?q=place%3A5122804691e5fecc' | jq '.statuses[].place.full_name'
    "Emeryville, CA"
    "San Francisco, CA"
    "South Beach, San Francisco"
    "San Francisco, CA"
    "San Francisco, CA"
    "Oakland, CA"
    "San Jose, CA"
    "Fremont, CA"
    "Richmond, CA"
    "San Leandro, CA"