私はEtsyAPIを使用して、ストアに新しいリストを追加しようとしています。ドキュメントのセクションにそれが書かれています(セクションの下のそれを行う方法)。最初のfyi私はこれまでHTTPメソッドを使用したことがないので、新しいアイテムを追加するようにコードを設定する方法がわかりません。
(Etsy APIページhttps://www.etsy.com/developers/documentation/reference/listingへのリンク)。
Method Name createListing
Synopsis Creates a new Listing.
HTTP Method POST
URI /listings
Parameters
Name Required Default Type
quantity Y int
title Y string
description Y text
price Y float
materials N array(string)
shipping_template_id N int
shop_section_id N int
image_ids N array(int)
is_customizable N boolean
non_taxable N boolean
image N image
state N active enum(active, draft)
processing_min N int
processing_max N int
category_id N int
taxonomy_id N int
tags N array(string)
who_made Y enum(i_did, collective, someone_else)
is_supply Y boolean
when_made Y enum(made_to_order, 2010_2017, 2000_2009, 1998_1999, before_1998, 1990_1997, 1980s, 1970s, 1960s, 1950s, 1940s, 1930s, 1920s, 1910s, 1900s, 1800s, 1700s, before_1700)
recipient N enum(men, women, unisex_adults, teen_boys, teen_girls, teens, boys, girls, children, baby_boys, baby_girls, babies, birds, cats, dogs, pets, not_specified)
occasion N enum(anniversary, baptism, bar_or_bat_mitzvah, birthday, canada_day, chinese_new_year, cinco_de_mayo, confirmation, christmas, day_of_the_dead, easter, eid, engagement, fathers_day, get_well, graduation, halloween, hanukkah, housewarming, kwanzaa, prom, july_4th, mothers_day, new_baby, new_years, quinceanera, retirement, st_patricks_day, sweet_16, sympathy, thanksgiving, valentines, wedding)
style N array(string)
Requires OAuth Y
Permission Scope listings_w
Notes
A shipping_template_id is required when creating a listing.
All listings created on www.etsy.com must be actual items for sale. Please see our guidelines for testingwith live listings.
Creating a listing creates a single inventory products with the supplied price and quantity. Use updateInventory to add more products.
私が知っているコードは次のようになります
import urllib
import requests
url = 'https://openapi.etsy.com/v2/listings/active?api_key={YOUR KEY HERE)' # I put my API key here
r = requests.get(url)
payload = {'quantity': '1', 'title': 'testdfsdfdfs0','description': 'dfsdfsdfsdfdsf','price': '2.55','who_made': 'i_did','is_supply': '0','when_made': '2010_2017'}
rrr = requests.post(url,payload)
print rrr # I get an error 404
Python HTTPメソッドを使用してEtsyで販売するアイテムを追加するにはどうすればよいですか?
from requests_oauthlib import OAuth1Session
import requests
from requests_oauthlib import OAuth1
import json
tempory_token_url = []
oauth_response_bucket = []
client_key = '.......'
client_secret = '......'
oauth = OAuth1Session(client_key, client_secret=client_secret)
request_token_url = 'https://openapi.etsy.com/v2/oauth/request_token?scope=email_r%20listings_r'
fetch_response = oauth.fetch_request_token(request_token_url)
resource_owner_key = fetch_response.get('oauth_token') # Have it
resource_owner_secret = fetch_response.get('oauth_token_secret')
oauth_url_temp = tempory_token_url[0]['login_urI']
base_authorization_url = oauth_url_temp
authorization_url = oauth.authorization_url(base_authorization_url)
redirect_response = raw_input('Paste the full redirect URL here: ')
oauth_response = oauth.parse_authorization_response(redirect_response)
verifier = oauth_response.get('oauth_verifier')
access_token_url = redeirect_response
oauth = OAuth1Session(client_key=client_secret=client_secret,resource_owner_key=resource_owner_key,resource_owner_secret=resource_owner_secret,verifier=verifier)
oauth_tokens = oauth.fetch_access_token(access_token_url)
resource_owner_key = oauth_tokens.get('oauth_token')
resource_owner_secret = oauth_tokens.get('oauth_token_secret')
これを機能させる方法はありますか?Etsy APIに関する情報はほとんどなく、ほとんどのものはPHPにあり、作業方法がわかりません。
今回はペイロードを変更しただけですが、403エラーが発生します。何が原因なのかわかりません。私の最善の推測は、oauth1.0を使用したもので、彼らのWebサイトではoauth1.1が必要だと言っていると思います。
設定方法は次のとおりですが、403エラーが発生します。
url = 'https://openapi.etsy.com/v2/listings'
payload = {'listing_id':'342434342', 'image': ("test1.jpg", open('C:\\Users\\abc\\test1.jpg'),'image/jpeg'),'type':'image/jpeg'}
result = etsy.put(url, params=payload)
print result
コメント:...この時点で私は迷子になっています。etsyがくれたピン番号をどこに置くべきかわかりません。
etsy oauth#reference
アカウントで受け取ったトークン認証情報は有効期限がなく、認証されたAPIリクエストを行うために何度も使用できます。トークンを安全な場所に秘密にして、プレーンテキストパラメータとして送信しないでください(リクエストの署名にのみ使用され、APIリクエストで単独で送信する必要はありません)。アクセスを取り消す場合、または追加のアクセス許可スコープを必要とする機能を追加しない限り、OAuth認証を再度実行します。
注:に相当する代替品が見つかりませんでした
PHP OAUTH_AUTH_TYPE_URI
。
OAuth1Session
デフォルトはsignature_type=u'AUTH_HEADER'
、なので、これは間違っている可能性があります。
これが失敗した場合は、次のことを試すことができます。from oauthlib.oauth1 import SIGNATURE_TYPE_QUERY, SIGNATURE_TYPE_BODY OAuth1Session(..., signature_type=SIGNATURE_TYPE_QUERY)
etsy OAuth1Session
リクエストに再利用するために作成:
etsy = OAuth1Session(client_key,
client_secret=client_secret,
resource_owner_key=resource_owner_key,
resource_owner_secret=resource_owner_secret)
etsy APIへの承認されたリクエストの作成:
response = etsy.get("https://openapi.etsy.com/v2/users/__SELF__")
user_data = json.loads(response.body_as_unicode())
etsy認証後のパーミッションスコープのチェック:
response = etsy.get("https://openapi.etsy.com/v2/oauth/scopes")
meta = json.loads(response.body_as_unicode())
etsyは新しいリストを作成します
url = 'https://openapi.etsy.com/v2/listings'
payload = {'quantity': '1', 'title':...}
result = etsy.post(url, params=payload)
コメント:APIキーの場合、oauth2をインポートする必要がありますか
参考文献によると、はい。
書き込みアクセスとプライベートユーザーデータへのアクセスには、OAuthアクセストークンが必要です。OAuth認証プロセスを開始するには、アプリケーションキーが必要です。
Requires OAuth Y
また、あなたurl
はで終わる必要があります
URI /listings
url = 'https://openapi.etsy.com/v2/listings'
URLは、疑問符までである必要があります。例:
url = 'https://openapi.etsy.com/v2/listings/active'
payload = {'api_key':YOUR KEY HERE, 'quantity': '1', ...
rrr = requests.post(url, params=payload)
クイックスタートのリクエスト:URLでのパラメーターの受け渡し
URLのクエリ文字列で何らかのデータを送信したい場合がよくあります。
URLを手動で作成している場合、このデータは、URLの疑問符の後にキーと値のペアとして表示されます(例:\ http://bin.org/get?key = val)。
リクエストでは、paramsキーワード引数を使用して、これらの引数を文字列のディクショナリとして提供できます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加