diff --git a/README.md b/README.md index c3fcca5..cbf80d1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Features - Twitter lists - Timelines - User avatar URL - - and anything found in [the docs](https://dev.twitter.com/docs/api) + - and anything found in [the docs](https://dev.twitter.com/docs/api/1.1) * Image Uploading! - **Update user status with an image** - Change user avatar @@ -57,7 +57,7 @@ from twython import Twython ''' oauth_token and oauth_token_secret come from the previous step -if needed, store those in a session variable or something +if needed, store those in a session variable or something. oauth_verifier from the previous call is now required to pass to get_authorized_tokens ''' t = Twython(app_key=app_key, @@ -65,7 +65,7 @@ t = Twython(app_key=app_key, oauth_token=oauth_token, oauth_token_secret=oauth_token_secret) -auth_tokens = t.get_authorized_tokens() +auth_tokens = t.get_authorized_tokens(oauth_verifier) print auth_tokens ``` @@ -90,16 +90,6 @@ t = Twython(app_key=app_key, print t.getHomeTimeline() ``` -###### Get a user avatar url *(no authentication needed)* - -```python -from twython import Twython - -t = Twython() -print t.getProfileImageUrl('ryanmcgrath', size='bigger') -print t.getProfileImageUrl('mikehelmick') -``` - ###### Streaming API *Usage is as follows; it's designed to be open-ended enough that you can adapt it to higher-level (read: Twitter must give you access) streams.* @@ -122,6 +112,8 @@ Twython.stream({ Notes ----- +Twython (as of 2.7.0) is currently in the process of ONLY supporting Twitter v1.1 endpoints and deprecating all v1 endpoints! Please see the **[Twitter v1.1 API Documentation](https://dev.twitter.com/docs/api/1.1)** to help migrate your API calls! + As of Twython 2.0.0, we have changed routes for functions to abide by the **[Twitter Spring 2012 clean up](https://dev.twitter.com/docs/deprecations/spring-2012)** Please make changes to your code accordingly. Development of Twython (specifically, 1.3) diff --git a/README.rst b/README.rst index 1bb6677..02cfa0a 100644 --- a/README.rst +++ b/README.rst @@ -10,7 +10,7 @@ Features - Twitter lists - Timelines - User avatar URL - - and anything found in `the docs `_ + - and anything found in `the docs `_ * Image Uploading! - **Update user status with an image** - Change user avatar @@ -58,7 +58,7 @@ Handling the callback ''' oauth_token and oauth_token_secret come from the previous step - if needed, store those in a session variable or something + if needed, store those in a session variable or something. oauth_verifier from the previous call is now required to pass to get_authorized_tokens ''' from twython import Twython @@ -67,7 +67,7 @@ Handling the callback oauth_token=oauth_token, oauth_token_secret=oauth_token_secret) - auth_tokens = t.get_authorized_tokens() + auth_tokens = t.get_authorized_tokens(oauth_verifier) print auth_tokens *Function definitions (i.e. getHomeTimeline()) can be found by reading over twython/twitter_endpoints.py* @@ -90,15 +90,6 @@ Getting a user home timeline # Returns an dict of the user home timeline print t.getHomeTimeline() -Get a user avatar url *(no authentication needed)* -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -:: - - from twython import Twython - - t = Twython() - print t.getProfileImageUrl('ryanmcgrath', size='bigger') - print t.getProfileImageUrl('mikehelmick') Streaming API ~~~~~~~~~~~~~ @@ -124,6 +115,8 @@ streams.* Notes ----- +* Twython (as of 2.7.0) is currently in the process of ONLY supporting Twitter v1.1 endpoints and deprecating all v1 endpoints! Please see the `Twitter API Documentation `_ to help migrate your API calls! + * As of Twython 2.0.0, we have changed routes for functions to abide by the `Twitter Spring 2012 clean up `_ Please make changes to your code accordingly. diff --git a/setup.py b/setup.py index a6bf312..d8f6863 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( include_package_data=True, # Package dependencies. - install_requires=['simplejson', 'requests>=1.0.0, <2.0.0', 'requests_oauthlib==0.3.0'], + install_requires=['requests>=1.0.0, <2.0.0', 'requests_oauthlib==0.3.0'], # Metadata for PyPI. author='Ryan McGrath', diff --git a/twython/twitter_endpoints.py b/twython/twitter_endpoints.py index ff78779..d946b25 100644 --- a/twython/twitter_endpoints.py +++ b/twython/twitter_endpoints.py @@ -9,7 +9,7 @@ will be replaced with the keyword that gets passed in to the function at call time. i.e, in this case, if I pass version = 47 to any function, {{version}} will be replaced - with 47, instead of defaulting to 1 (said defaulting takes place at conversion time). + with 47, instead of defaulting to 1.1 (said defaulting takes place at conversion time). This map is organized the order functions are documented at: https://dev.twitter.com/docs/api/1.1 @@ -87,7 +87,7 @@ api_table = { 'method': 'GET', }, 'destroyDirectMessage': { - 'url': '/direct_messages/destroy/{{id}}.json', + 'url': '/direct_messages/destroy.json', 'method': 'POST', }, 'sendDirectMessage': { @@ -183,11 +183,11 @@ api_table = { 'method': 'GET', }, 'createBlock': { - 'url': '/blocks/create/{{id}}.json', + 'url': '/blocks/create.json', 'method': 'POST', }, 'destroyBlock': { - 'url': '/blocks/destroy/{{id}}.json', + 'url': '/blocks/destroy.json', 'method': 'POST', }, 'lookupUser': { @@ -215,6 +215,10 @@ api_table = { 'method': 'POST', }, # See twython.py for update_profile_banner + 'getProfileBannerSizes': { + 'url': '/users/profile_banner.json', + 'method': 'GET', + }, # Suggested Users diff --git a/twython/twython.py b/twython/twython.py index 2e27ee5..b189d3f 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -26,17 +26,9 @@ except ImportError: from twitter_endpoints import base_url, api_table, twitter_http_status_codes try: - import simplejson + import simplejson as json except ImportError: - try: - # Python 2.6 and up - import json as simplejson - except ImportError: - try: - from django.utils import simplejson - except: - # Seriously wtf is wrong with you if you get this Exception. - raise Exception("Twython requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/") + import json class TwythonError(Exception): @@ -194,7 +186,7 @@ class Twython(object): # why? twitter will return invalid json with an error code in the headers json_error = False try: - content = simplejson.loads(content) + content = content.json() except ValueError: json_error = True content = {} @@ -437,13 +429,13 @@ class Twython(object): **params - You may pass items that are taken in this doc (https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media) """ - subdomain = 'upload' if version == '1' else 'api' - url = 'https://%s.twitter.com/%s/statuses/update_with_media.json' % (subdomain, version) + + url = 'https://api.twitter.com/%s/statuses/update_with_media.json' % version return self._media_update(url, {'media': (file_, open(file_, 'rb'))}, **params) - def updateProfileBannerImage(self, file_, version=1, **params): + def updateProfileBannerImage(self, file_, version='1.1', **params): """Updates the users profile banner :param file_: (required) A string to the location of the file @@ -453,7 +445,7 @@ class Twython(object): **params - You may pass items that are taken in this doc (https://dev.twitter.com/docs/api/1/post/account/update_profile_banner) """ - url = 'https://api.twitter.com/%d/account/update_profile_banner.json' % version + url = 'https://api.twitter.com/%s/account/update_profile_banner.json' % version return self._media_update(url, {'banner': (file_, open(file_, 'rb'))}, **params) @@ -518,7 +510,7 @@ class Twython(object): for line in stream.iter_lines(): if line: try: - callback(simplejson.loads(line)) + callback(json.loads(line)) except ValueError: raise TwythonError('Response was not valid JSON, unable to decode.')