xitiomet / python-twitter

fork of python-twitter

Mostly the same, but i added support for Mentions http://apiwiki.twitter.com/Twitter-REST-API-Met...

Clone this repository (size: 393.3 KB): HTTPS / SSH
$ hg clone http://hg.openstatic.org/python-twitter
commit 127: c05534ecbc50
parent 126: fa53aa14dce8
branch: dclinton
Implemented the VerifyCredentials api method
dcli...@b35c0ba3-1128-0410-9219-0b39014e361d
14 months ago

Changed (Δ734 bytes):

raw changeset »

twitter.py (22 lines added, 0 lines removed)

Up to file-list twitter.py:

@@ -29,6 +29,7 @@ import sys
29
29
import tempfile
30
30
import textwrap
31
31
import time
32
import httplib
32
33
import urllib
33
34
import urllib2
34
35
import urlparse
@@ -936,6 +937,27 @@ class Api(object):
936
937
    self._CheckForTwitterError(data)
937
938
    return NewResultsFromJsonDict(data)
938
939
940
  def VerifyCredentials(self):
941
    '''Returns a twitter.User instance if the authenticating user is valid.
942
943
    Returns: 
944
      A twitter.User instance representing that user if the
945
      credentials are valid, None otherwise.
946
    '''
947
    if not self._username:
948
      raise TwitterError("Api instance must first be given user credentials.")
949
    url = 'http://twitter.com/account/verify_credentials.json'
950
    try:
951
      json = self._FetchUrl(url, no_cache=True)
952
    except urllib2.HTTPError, http_error:
953
      if http_error.code == httplib.UNAUTHORIZED:
954
        return None
955
      else:
956
        raise http_error
957
    data = simplejson.loads(json)
958
    self._CheckForTwitterError(data)
959
    return NewUserFromJsonDict(data)
960
939
961
  def SetCredentials(self, username, password):
940
962
    '''Set the username and password for this instance
941
963