Permalink
Browse files

fixing code examples alignment

  • Loading branch information...
1 parent 73eab90 commit c3ac25496cf1a624fb1988145e585f860ebeb4e5 @maxcountryman maxcountryman committed Jun 15, 2012
Showing with 37 additions and 37 deletions.
  1. +37 −37 README.markdown
View
@@ -32,65 +32,65 @@ Let's get a user's Twitter timeline. Start by creating a service container
object:
```python
- from rauth.service import OAuth1Service
-
- # Get a real consumer key & secret from https://dev.twitter.com/apps/new
- twitter = OAuth1Service(
- name='twitter',
- consumer_key='YOUR_CONSUMER_KEY',
- consumer_secret='YOUR_CONSUMER_SECRET',
- request_token_url='https://api.twitter.com/oauth/request_token',
- access_token_url='https://api.twitter.com/oauth/access_token',
- authorize_url='https://api.twitter.com/oauth/authorize',
- header_auth=True)
+from rauth.service import OAuth1Service
+
+# Get a real consumer key & secret from https://dev.twitter.com/apps/new
+twitter = OAuth1Service(
+ name='twitter',
+ consumer_key='YOUR_CONSUMER_KEY',
+ consumer_secret='YOUR_CONSUMER_SECRET',
+ request_token_url='https://api.twitter.com/oauth/request_token',
+ access_token_url='https://api.twitter.com/oauth/access_token',
+ authorize_url='https://api.twitter.com/oauth/authorize',
+ header_auth=True)
```
Then get an OAuth 1.0 request token:
```python
- request_token, request_token_secret = \
- twitter.get_request_token(method='GET')
+request_token, request_token_secret = \
+ twitter.get_request_token(method='GET')
```
Go through the authentication flow. Since our example is a simple console
application, Twitter will give you a PIN to enter.
```python
- authorize_url = twitter.get_authorize_url(request_token)
+authorize_url = twitter.get_authorize_url(request_token)
- print 'Visit this URL in your browser: ' + authorize_url
- pin = raw_input('Enter PIN from browser: ')
+print 'Visit this URL in your browser: ' + authorize_url
+pin = raw_input('Enter PIN from browser: ')
```
Exchange the authorized request token for an access token:
```python
- response = twitter.get_access_token('GET',
- request_token=request_token,
- request_token_secret=request_token_secret,
- params={'oauth_verifier': pin})
- data = response.content
-
- access_token = data['oauth_token']
- access_token_secret = data['oauth_token_secret']
+response = twitter.get_access_token('GET',
+ request_token=request_token,
+ request_token_secret=request_token_secret,
+ params={'oauth_verifier': pin})
+data = response.content
+
+access_token = data['oauth_token']
+access_token_secret = data['oauth_token_secret']
```
And now we can fetch our Twitter timeline!
```python
- params = {'include_rts': 1, # Include retweets
- 'count': 10} # 10 tweets
-
- response = twitter.get('https://api.twitter.com/1/statuses/home_timeline.json',
- params=params,
- access_token=access_token,
- access_token_secret=access_token_secret,
- header_auth=True)
-
- for i, tweet in enumerate(response.content, 1):
- handle = tweet['user']['screen_name'].encode('utf-8')
- text = tweet['text'].encode('utf-8')
- print '{0}. @{1} - {2}'.format(i, handle, text)
+params = {'include_rts': 1, # Include retweets
+ 'count': 10} # 10 tweets
+
+response = twitter.get('https://api.twitter.com/1/statuses/home_timeline.json',
+ params=params,
+ access_token=access_token,
+ access_token_secret=access_token_secret,
+ header_auth=True)
+
+for i, tweet in enumerate(response.content, 1):
+ handle = tweet['user']['screen_name'].encode('utf-8')
+ text = tweet['text'].encode('utf-8')
+ print '{0}. @{1} - {2}'.format(i, handle, text)
```
The full example is in [examples/twitter-timeline.py](https://github.com/litl/rauth/blob/master/examples/twitter-timeline.py).

0 comments on commit c3ac254

Please sign in to comment.