Created
March 2, 2012 22:45
-
-
Save toffer/1962023 to your computer and use it in GitHub Desktop.
Use OAuth with slumber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# An example of modifying the session of a slumber.API instance, | |
# in order to use OAuth authentication and turn on verbose logging. | |
import requests | |
import slumber | |
import sys | |
# from https://github.com/maraujop/requests-oauth | |
from oauth_hook import OAuthHook | |
# These shouldn't be blank... | |
CONSUMER_KEY = '' | |
CONSUMER_SECRET = '' | |
ACCESS_TOKEN = '' | |
ACCESS_SECRET = '' | |
def twitter_test(): | |
"""Access Twitter API with slumber.""" | |
hook = OAuthHook(access_token=ACCESS_TOKEN, | |
access_token_secret=ACCESS_SECRET, | |
consumer_key=CONSUMER_KEY, | |
consumer_secret=CONSUMER_SECRET, | |
header_auth=False) | |
sess = requests.session(hooks={'pre_request': hook}, config={'verbose': sys.stderr}) | |
api = slumber.API('https://api.twitter.com/1/', append_slash=False) | |
api._store['session'] = sess | |
print api.statuses("home_timeline.json").get() | |
print api.statuses("home_timeline.json").get(count=1, include_entities='true') | |
def main(): | |
twitter_test() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment