pyfoo / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

Add friendship exist #126

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
There is no API to check friendship of two users, but twitter provides:

http://twitter.com/friendships/exists.json?user_a=xxx&user_b=xxx

returns:

true|false

Here is my modification:

  def GetFriendshipExists(self, user_a, user_b):
    '''Tests for the existence of friendship between two users.
    Will return true if user_a follows user_b, otherwise will return false.

    The twitter.Api instance must be authenticated.

    Args:
      The ID or screen name of the user to befriend.
    Returns:
      Tuple of (True|False, True|False) if source following target, target 
following source.
    '''
    url = 'http://twitter.com/friendships/exists.json'
    parameters = {}
    parameters['user_a'] = user_a
    parameters['user_b'] = user_b
    json = self._FetchUrl(url, parameters=parameters)
    data = simplejson.loads(json)
    if type(data)==type(True):
        return data
    self._CheckForTwitterError(data)

Original issue reported on code.google.com by askxuefeng@gmail.com on 23 Feb 2010 at 8:56

GoogleCodeExporter commented 9 years ago
sorry the doc of function is not accurate.

  '''Tests for the existence of friendship between two users.
    Will return true if user_a follows user_b, otherwise will return false.

    Args:
      user_a User A's screen name
      user_b User B's screen name

    Returns:
      True if user_a is following user_b
    '''

Original comment by askxuefeng@gmail.com on 23 Feb 2010 at 8:58