我試圖使用Etsy API(HTTP方法)在我的商店中添加一個新的列表。它在文檔部分說(下面的部分是怎麼做的)。首先,我從來沒有使用HTTP方法,所以我不知道如何設置代碼,以便它添加一個新的項目。 (鏈接到Etsy的API頁面https://www.etsy.com/developers/documentation/reference/listing)python etsy HTTP方法api幫助需要添加新項目
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
誰能告訴我一個正確的方法,我可以上出售的Etsy通過蟒蛇添加項目HTTP方法。謝謝
更新:
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中,我不知道如何僅僅使用python。
圖片上傳API幫助。
一切看起來都像上面這樣,我只是改變了有效載荷,但我得到了一個403錯誤。我不確定是什麼原因造成的。我最好的猜測會是oauth1.0的東西,我認爲那裏的網站上說你需要oauth 1.1。這裏是我如何設置它,但我正在逐漸403error:
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
for api key我需要導入oauth2還是可以使用etsty爲我的帳戶提供的密鑰和密鑰。現在,我想在我的商店上發佈錯誤消息。 。我希望這個問題有道理,我一直試圖弄清楚這一整天......燒壞了。 –
感謝您的更新。我有點卡在Ouath部分「https://www.etsy.com/developers/documentation/getting_started/oauth」我已經成功地從etsy完成了第1步(稱爲 - 授權請求)我得到一個鏈接,然後我批准了像pictue這樣的請求,它給了我一個引腳。在這一點上,我迷路了,我不知道在哪裏放置etsy給我的pin。我會更新我的頁面,讓你知道我的意思。 –
完美無瑕的解釋你是一個救星。謝謝 –