Fix Advanced docs Twitter Streaming example
authorMike Helmick <mikeh@ydekproductions.com>
Thu, 11 Apr 2013 03:49:27 +0000 (00:49 -0300)
committerMike Helmick <mikehelmick@me.com>
Fri, 12 Apr 2013 00:19:51 +0000 (20:19 -0400)
Twitter API v1.1 Streaming now requires OAuth Authentication rather than XAuth.
I believe v1 is being blacked out sometime at the beginning of May.

docs/user/advanced.rst
docs/user/authentication.rst

index 21bfa7ba1547e3db3a8b321bc47858afba7bba0b..79c9d414d31b9f57ef4434bcb210739e6f1df743 100644 (file)
@@ -278,9 +278,17 @@ To use the Twitter Streaming API to track the keyword "requests"::
 
     import requests
     import json
+    from requests_oauthlib import OAuth1
 
-    r = requests.post('https://stream.twitter.com/1/statuses/filter.json',
-        data={'track': 'requests'}, auth=('username', 'password'), stream=True)
+    app_key = 'YOUR_APP_KEY'
+    app_secret = 'YOUR_APP_SECRET'
+    oauth_token = 'USER_OAUTH_TOKEN'
+    oauth_token_secret = 'USER_OAUTH_TOKEN_SECRET'
+
+    auth = OAuth1(app_key, app_secret, oauth_token, oauth_token_secret)
+
+    r = requests.post('https://stream.twitter.com/1.1/statuses/filter.json',
+                      data={'track': 'requests'}, auth=auth, stream=True)
 
     for line in r.iter_lines():
         if line: # filter out keep-alive new lines
index a3b5b56d7893093b7d821edc0556c0fe23efd061..d25f373c51354b5fb9c12ba6895119bc8b68cdf5 100644 (file)
@@ -44,6 +44,25 @@ and Requests supports this out of the box as well::
     <Response [200]>
 
 
+OAuth 1 Authentication
+----------------------
+
+A common form of authentication for several web APIs is OAuth. The ``requests-oauthlib`` library allows Requests users to easily make OAuth authenticated requests::
+
+    >>> import request
+    >>> from requests_oauthlib import OAuth1
+
+    >>> url = 'https://api.twitter.com/1.1/account/verify_credentials.json'
+    >>> auth = OAuth1('YOUR_APP_KEY', 'YOUR_APP_SECRET',
+                      'USER_OAUTH_TOKEN', 'USER_OAUTH_TOKEN_SECRET')
+
+    >>> requests.get(url, auth=auth)
+    <Response [200]>
+
+For more information on how to OAuth flow works, please see the official `OAuth`_ website.
+For examples and documentation on requests-oauthlib, please see the `requests_oauthlib`_ repository on GitHub
+
+
 Other Authentication
 --------------------
 
@@ -53,7 +72,6 @@ authentication handlers for more complicated or less commonly-used forms of
 authentication. Some of the best have been brought together under the
 `Requests organization`_, including:
 
-- OAuth_
 - Kerberos_
 - NTLM_
 
@@ -77,7 +95,8 @@ authentication will additionally add hooks to provide further functionality.
 Examples can be found under the `Requests organization`_ and in the
 ``auth.py`` file.
 
-.. _OAuth: https://github.com/requests/requests-oauthlib
+.. _OAuth: http://oauth.net/
+.. _requests_oauthlib: https://github.com/requests/requests-oauthlib
 .. _Kerberos: https://github.com/requests/requests-kerberos
 .. _NTLM: https://github.com/requests/requests-ntlm
 .. _Requests organization: https://github.com/requests