문서에서이 차이를 지적 해 주셔서 감사합니다. 아래의 함수는 파이썬 라이브러리 Requests을 사용하여 항목의 이미지를 업로드합니다 (이 라이브러리는 multipart/form-data 요청을 훨씬 간단하게 만듭니다). 처음에는 install Requests이 필요합니다.
import requests
def upload_item_image(item_id, image_path, access_token):
endpoint_path = 'https://connect.squareup.com/v1/me/items/' + item_id + '/image'
# Don't include a Content-Type header, because the Requests library adds its own
upload_request_headers = {'Authorization': 'Bearer ' + access_token,
'Accept': 'application/json'}
# Be sure to set the correct MIME type for the image
files = [('image_data', (image_path, open(image_path, 'rb'), "image/jpeg"))]
response = requests.post(endpoint_path, files=files, headers=upload_request_headers)
# Print the response body
print response.text
item_id
당신에 대한 이미지를 업로드 할 항목의 ID입니다.
image_path
은 업로드하는 이미지의 상대 경로입니다.
access_token
은 귀하가 대리하는 판매자의 액세스 토큰입니다.
단일 요청에서 여러 항목에 대한 이미지를이 끝점으로 업로드 할 수 없습니다. 대신 각 항목에 대해 별도의 요청을 보냅니다.
답장을 보내 주신 Stephen에게 감사드립니다. 불행히도, 나는 이것을 작동시키지 못합니다. 코드를 실행하면 아무 일도 일어나지 않고 실행됩니다. 그 코드의 마지막 줄에서 괄호와 관련된 문법 오류를 얻었습니다 : print (response.text()). 작동 시키려면 수정이 필요한 코드에 표시되는 것이 있습니까? 도와 주셔서 미리 감사드립니다. – Accounting