Tôi đã đập đầu vào tường để tìm ra cách gửi yêu cầu được xác thực với oauth.Cách gửi yêu cầu oauth bằng python-oauth2
Tôi đã có thể nhận mã thông báo truy cập, nhưng không hoàn toàn chắc chắn cách gửi yêu cầu với họ. Tôi thấy điều này trên thông tin nhà phát triển của twitter của:
https://dev.twitter.com/docs/auth/oauth/single-user-with-examples#python trong đó có một số mã ví dụ cho việc gửi một yêu cầu ủy quyền:
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,
#force_auth_header=True
)
return resp,content
oauth_req('http://openapi.etsy.com/v2/shops/:user/transactions',tokenKey,tokenSecret)
Tuy nhiên, khi tôi bao gồm tất cả các thông tin của tôi, tôi nhận được lỗi sau:
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'
trong đó: người dùng là người dùng thực tế (tôi đã xóa nó khỏi bài đăng) và tokenKey/tokenSecret là mã thông báo truy cập.
Tôi nghĩ có lẽ đó là đơn giản như cho ý kiến ra dòng vi phạm, nhưng không có may mắn như vậy:
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
Vì vậy, bây giờ, stackoverflow, bạn là hy vọng duy nhất của tôi! Bất kỳ ai cũng có đề xuất về cách sử dụng mã thông báo truy cập của tôi để gửi yêu cầu?
cảm ơn!
bạn có thể đăng mã của mình không? không thực sự có thể giúp đỡ mà không có nó – jterrace
Mã này giống như từ liên kết trong bài đăng gốc. Tôi đã chỉnh sửa bài gốc để chứa mã; cảm ơn! –