I banged my head against the wall, trying to figure out how to send authenticated requests using oauth.
I managed to get access tokens, but I'm not quite sure how to send a request with them. I found this in twitter developer info:
https://dev.twitter.com/docs/auth/oauth/single-user-with-examples#python which has an example code for sending an authorized request:
def oauth_req(url, key, secret, http_method="GET", post_body=None,http_headers=None): consumer = oauth.Consumer(key=consumerKey, secret=consumerSecret) token = oauth.Token(key=tokenKey, secret=tokenSecret) client = oauth.Client(consumer, token) resp, content = client.request( url, method=http_method, body=post_body, headers=http_headers,
However, when I included all my information, I received the following error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/tmp/python-22060Umg.py", line 153, in <module> transactions = oauth_req('http://openapi.etsy.com/v2/shops/:user/transactions',tokenKey,tokenSecret) File "/tmp/python-22060Umg.py", line 76, in oauth_req force_auth_header=True TypeError: request() got an unexpected keyword argument 'force_auth_header'
where: the user is the actual user (I removed it from the message), and tokenKey / tokenSecret are access tokens.
I thought that perhaps it was as simple as commenting on an offensive line, but there wasn’t such luck:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/tmp/python-22060hwm.py", line 153, in <module> transactions = oauth_req('http://openapi.etsy.com/v2/shops/:user/transactions',tokenKey,tokenSecret) File "/tmp/python-22060hwm.py", line 75, in oauth_req headers=http_headers File "/usr/lib/python2.7/dist-packages/oauth2/__init__.py", line 662, in request req.sign_request(self.method, self.consumer, self.token) File "/usr/lib/python2.7/dist-packages/oauth2/__init__.py", line 493, in sign_request self['oauth_body_hash'] = base64.b64encode(sha(self.body).digest()) TypeError: must be string or buffer, not None
So, stackoverflow, you are my only hope! Anyone have any suggestions on using my access token to send a request?
thanks!