Shopify API怎么用?如何使用shopify SDK API

Shopify Python API SDK 安装

https://github.com/Shopify/shopify_python_api

pip3 install --upgrade ShopifyAPI 

授权认证

这里是私有应用的授权方式

import shopify

API_KEY = 'xxxxxxxxxxxxxxxxxxxxx'
PASSWORD = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
API_VERSION = '2020-04'

shop_url = "https://%s:%s@你的名称.myshopify.com/admin/api/%s" % (
    API_KEY, PASSWORD, API_VERSION)

shopify.ShopifyResource.set_site(shop_url) 

获取当前shopify店铺

shop = shopify.Shop.current()
print(shop) 

修改产品测试

product = shopify.Product.find(5287207567524)

print('修改前:' + product.title)

product.title = 'shopify api product name test 2'
product.save()

product = shopify.Product.find(5287207567524)
print('修改后:' + product.title) 

遍历shopify店铺全部产品

单页返回50个

page1 = shopify.Product.find()

# 获取下一页方式 1 
if page1.has_next_page():
    page2 = page1.next_page()

# 获取下一页方式 2
next_url = page1.next_page_url
page2 = shopify.Product.find(from_=next_url)
print(page2)