python-500px
python-500px copied to clipboard
HTTP Error 401: Unauthorized
I trying yo use the api for 500px but i have some troubles, in the first step all is fine, i can generate OAuthHandler handler and get the url authorization then redirect the user to it, but when 500px.com redirect to my app and i try to create again the OAuthHandler next i try to pass the oauth_verifier to new handler but the 500px response me "HTTP Error 401: Unauthorized" and i don't know why
class FiveHundredpx(web.RequestHandler):
def get(self):
oauth_token = self.get_argument('oauth_token', None)
oauth_verifier = self.get_argument('oauth_verifier', None)
if not oauth_verifier:
handler = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
token = handler.get_request_token()
self.set_cookie('oauth_token', token.key)
self.set_cookie('oauth_token_secret', token.secret)
self.redirect(handler.get_authorization_url()+'&display=popup')
else:
handler = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
handler.set_request_token(self.get_cookie('oauth_token'), self.get_cookie('oauth_token_secret'))
handler.set_access_token(oauth_token, self.get_cookie('oauth_token_secret'))
handler.get_access_token(oauth_verifier)
unauthorized_api = FiveHundredPXAPI(handler)
@oamm you can't get access token by passing verifier?
I can run this code perfectly
from fivehundredpx.client import FiveHundredPXAPI
from fivehundredpx.auth import *
CONSUMER_KEY = 'XXXXXX'
CONSUMER_SECRET = 'XXXX'
handler = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
token = handler.get_request_token()
handler.set_request_token(key=token.key, secret=token.secret)
handler.get_authorization_url()
#I got the url and pass the oauth_verifier(YYYYYY)
token = handler.get_access_token('YYYYYY')
handler.set_access_token(token.key, token.secret)
api = FiveHundredPXAPI(handler)
api.users()['user']['domain']
>>u'OmarMora.500px.com'
But i don't know how create a new instance of the OAuthHandler and pass the oauth_verifier parameter to it for continue the authentication, I tried to do it with the code that is above but i still get FiveHundredClientError: HTTP Error 401: Unauthorized , if you can tell me how is the correct order that i have to send the outh_verifier and tokens I would be very greatful
@oamm you can get data from 500px api normally when u make first request after getting access token. and when u make second request with new instance of API client, you get 401 error. is this correct?
if so, you can just set access token again. but u have to keep the access token somewhere.
CONSUMER_KEY = 'XXXXXX'
CONSUMER_SECRET = 'XXXX'
handler = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
handler.set_access_token( "key", "secret")
api = FiveHundredPXAPI(handler)