Created
January 8, 2013 13:10
-
-
Save trtg/4483703 to your computer and use it in GitHub Desktop.
mendeley oauth python client using rauth note the comments on web flow vs app flow
This file contains hidden or 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
from rauth.service import OAuth1Service | |
from credentials import consumer_key,consumer_secret | |
mendeley = OAuth1Service( | |
name='mendeley', | |
consumer_key=consumer_key, | |
consumer_secret=consumer_secret, | |
request_token_url='http://api.mendeley.com/oauth/request_token/', | |
access_token_url='http://api.mendeley.com/oauth/access_token/', | |
authorize_url='http://api.mendeley.com/oauth/authorize/', | |
header_auth=True) | |
#if you specify oauth_callback parameter to get_request_token then you will get the web flow with redirect | |
#if you do NOT specify oauth_callback parameter then you will get installed app flow with just a verification code | |
#request_token, request_token_secret = mendeley.get_request_token(method='GET',oauth_callback="http://localhost/callback/mendeley") | |
request_token, request_token_secret = mendeley.get_request_token(method='GET') | |
authorize_url = mendeley.get_authorize_url(request_token,redirect_uri="http://localhost/callback/mendeley") | |
print 'Visit this URL in your browser: ' + authorize_url | |
pin = raw_input('Enter PIN from browser: ') | |
response = mendeley.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'] | |
print "access_token: ",access_token | |
print "access_token_secret: ",access_token_secret | |
params = {} | |
response = mendeley.get('http://api.mendeley.com/oapi/library/', | |
params=params, | |
access_token=access_token, | |
access_token_secret=access_token_secret, | |
header_auth=True) | |
print response.content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment