Skip to content
Myr

Merge pull request #1305 from michaelhelmick/patch-1

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix Advanced docs Twitter Streaming example

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 561366c, ed0242a · Browse files · 2 files+31 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+31 added−4 removed

  • other:+31 added−4 removed

2 files+31 added−4 removed

modified:docs/user/advanced.rst+10 added-2 removed
276 unmodified lines
277To use the Twitter Streaming API to track the keyword "requests"::278279 import requests280 import json281 from requests_oauthlib import OAuth1282282 r = requests.post('https://stream.twitter.com/1/statuses/filter.json',283 data={'track': 'requests'}, auth=('username', 'password'), stream=True)283 app_key = 'YOUR_APP_KEY'284 app_secret = 'YOUR_APP_SECRET'285 oauth_token = 'USER_OAUTH_TOKEN'286 oauth_token_secret = 'USER_OAUTH_TOKEN_SECRET'287288 auth = OAuth1(app_key, app_secret, oauth_token, oauth_token_secret)289290 r = requests.post('https://stream.twitter.com/1.1/statuses/filter.json',291 data={'track': 'requests'}, auth=auth, stream=True)292293 for line in r.iter_lines():294 if line: # filter out keep-alive new lines295 print json.loads(line)296
287 unmodified lines
modified:docs/user/authentication.rst+21 added-2 removed
42 unmodified lines
43 >>> requests.get(url, auth=HTTPDigestAuth('user', 'pass'))44 <Response [200]>454647OAuth 1 Authentication48----------------------4950A common form of authentication for several web APIs is OAuth. The ``requests-oauthlib`` library allows Requests users to easily make OAuth authenticated requests::5152 >>> import request53 >>> from requests_oauthlib import OAuth15455 >>> url = 'https://api.twitter.com/1.1/account/verify_credentials.json'56 >>> auth = OAuth1('YOUR_APP_KEY', 'YOUR_APP_SECRET',57 'USER_OAUTH_TOKEN', 'USER_OAUTH_TOKEN_SECRET')5859 >>> requests.get(url, auth=auth)60 <Response [200]>6162For more information on how to OAuth flow works, please see the official `OAuth`_ website.63For examples and documentation on requests-oauthlib, please see the `requests_oauthlib`_ repository on GitHub646566Other Authentication67--------------------6869Requests is designed to allow other forms of authentication to be easily and
1 unmodified line
71authentication handlers for more complicated or less commonly-used forms of72authentication. Some of the best have been brought together under the73`Requests organization`_, including:7456- OAuth_75- Kerberos_76- NTLM_7778If you want to use any of these forms of authentication, go straight to their
15 unmodified lines
9495Examples can be found under the `Requests organization`_ and in the96``auth.py`` file.9798.. _OAuth: http://oauth.net/80.. _OAuth: https://github.com/requests/requests-oauthlib99.. _requests_oauthlib: https://github.com/requests/requests-oauthlib100.. _Kerberos: https://github.com/requests/requests-kerberos101.. _NTLM: https://github.com/requests/requests-ntlm102.. _Requests organization: https://github.com/requests103