如何使用Etsy API凭据在python中获取和发布数据 [英] How to use Etsy API credentials to GET and POST data in python

查看:78
本文介绍了如何使用Etsy API凭据在python中获取和发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将产品配置数据库与POS和各种电子商务站点链接起来.拼图中的最后一个链接是连接到Etsy.他们的指南( https://www.etsy.com/developers/documentation/reference/listing)特定于PHP,但我正在使用python 3.7.

I am working at linking my product configuration database with my POS and various eCommerce sites. The last link in the puzzle is connecting to Etsy. Their guide (https://www.etsy.com/developers/documentation/reference/listing) is specific to PHP, but I am working with python 3.7.

由于以下问题,我已经能够成功获取所需的凭据:

I have been able to successfully acquire the credentials required thanks to this question: How to add a new item using Python Etsy HTTP API methods? I now have the following credentials:

  • oauth_token
  • oauth_token_secret
  • oauth_consumer_key
  • 验证程序
  • key_string
  • shared_secret
  • oauth_token
  • oauth_token_secret
  • oauth_consumer_key
  • verifier
  • key_string
  • shared_secret

我尝试同时使用 python_etsy etsy_python ,但是两者似乎都已被放弃并且不完整,每当产生异常.我尽了最大的能力尝试解决每一个出现的问题,但是却迷失了.

I tried using both python_etsy and etsy_python, but both seem to have been abandoned and are incomplete, producing exceptions at every turn. I tried to my best ability to try to fix each issue as it arises, but am just so lost.

我只是不知道如何正确使用给定的凭据才能对Etsy API进行成功的API调用.

I just don't know how to properly use the given credentials in order to make successful API calls to the Etsy API.

即使在定义 OAuth1Session 对象 etsy 时添加 signature_type = SIGNATURE_TYPE_QUERY ,也会产生相同的结果.

Even adding signature_type=SIGNATURE_TYPE_QUERY when defining the OAuth1Session object etsy produces the same result.

由于

I am posting this as a new question, since the question linked above is specific to adding a new item using the API, while I am looking for general instruction on interpreting and converting the PHP examples for use in Python. This is what I have done with other APIs with good success, but this particular one has thrown be for a loop.

verifier 在哪里播放?

我使用 requests.get 代替了 oauth 会话,如下所示:

In place of an oauth session, I used requests.get as follows:

>>> import requests
>>> import uuid
>>> from datetime import datetime
>>> url = 'https://openapi.etsy.com/v2/oauth/access_token'
>>> params = {
...  'oauth_consumer_key': {oauth_consumer_key},
...  'oauth_signature': {verifier},
...  'oauth_signature_method': {method},
...  'oauth_nonce': str(uuid(uuid1()),
...  'oauth_timestamp': datetime.timestamp(datetime.utcnow())
...  'oauth_token': {oauth_token}
...}
>>> token_response = requests.get(url,params=params)
>>> print(rrr.status_code,rrr.text)
400 oauth_problem=verifier_invalid

我尝试使用以下每个值作为 oauth_signature_method 的上述方法:

I tried the above using each of the following value for oauth_signature_method:

  • "PLAINTEXT"
  • 'RSA-SHA1'
  • 'HMAC-SHA1'

每个值产生相同的结果.我还尝试将 verifier 放在 oauth_nonce 参数

Each value produced the same result. I also tried placing the verifier in the oauth_nonce paramater

推荐答案

使用 etsy-python2 模块来获取和处理凭据.

Use etsy-python2 module to acquire and process the credentials.

pip install etsy2

从etsy2

from etsy2 import Etsy
from etsy2.oauth import EtsyOAuthHelper, EtsyOAuthClient
import urllib.parse as urlparse
from urllib.parse import parse_qs

api_key = <etsy keystring>
shared_secret = <etsy shared secret>

#define permission scopes
permission_scopes = ['listings_r', 'listings_w']

login_url, temp_oauth_token_secret = \
    EtsyOAuthHelper.get_request_url_and_token_secret(api_key, shared_secret, permission_scopes)

query = urlparse.urlparse(login_url).query
temp_oauth_token = parse_qs(query)['oauth_token'][0]

print(login_url)
#follow the url to acquire the verifier.

oauth_token, oauth_token_secret = \
    EtsyOAuthHelper.get_oauth_token_via_verifier(api_key, shared_secret, temp_oauth_token, temp_oauth_token_secret, input('Verifier: '))

etsy_oauth = EtsyOAuthClient(client_key = api_key,
                             client_secret = shared_secret,
                             resource_owner_key = oauth_token,
                             resource_owner_secret = oauth_token_secret)

etsy = Etsy(etsy_oauth_client = etsy_oauth)

etsy2 模块是最新的并且正在维护中,所以现在,这是一个不错的选择.这些方法是在运行时从Etsy的API服务器动态定义的.定义 Etsy 对象后,您可以使用以下方法列出可用的方法:

The etsy2 module is current and being maintained, so right now, it is a good option. The methods are dynamicly defined at runtime from Etsy's API server. After defining your Etsy object, you can list the available methods using:

dir(etsy)

这篇关于如何使用Etsy API凭据在python中获取和发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆