我创建了一个shopify应用程序来读取商店数据,如类别名称,产品名称等 . 遵循本指南https://help.shopify.com/api/getting-started/authentication/oauth
我已经在python中编写了脚本以使OAUTH请求在shopify商店中安装我的应用程序 . 我在OAuth请求期间使用api密钥,密钥,并在合作伙伴信息中心的应用程序中设置应用程序URL,白名单重定向URL . 这里发生了两种情况:
-
第一种情况是商店所有者登录到商店时OAuth请求被授予并重定向到应用程序安装页面,安装后重定向到使用OAuth请求URL传递的redirect_url .
-
第二种情况是商店所有者未登录商店OAuth请求重定向到商店登录页面,登录页面重定向到商店的管理仪表板 . 不会重定向到应用程序安装页面 .
第一种情况没问题 . 我一直试图解决第二种情况 . 登录到商店后,我想重定向到应用程序安装页面 .
除了我,其他shopify开发人员正面临着这个问题 . 这里是shopify论坛中另外2个未答复的相同问题的链接 .
我试过的:
我想在django做这件事 . 这里是我试图将用户重定向到shopify商店进行授权的代码 .
def redirect_to_shopify_store(request):
redirect_url = "https://" + store_name + ".myshopify.com/admin/oauth/authorize?client_id=" + api_key
redirect_url += "&scope=read_orders, write_checkouts, read_themes, write_themes, read_products, write_products, unauthenticated_read_product_listings, read_product_listings, read_collection_listings"
redirect_url += "&redirect_uri=" + python_app_base_url + "/get_shopify_access_token/"
redirect(redirect_url)
这是我试图接收shopify访问令牌的代码:
def get_shopify_access_token(request):
code = request.GET.get('code')
client_id = shopify_config['client_id']
request_url = "https://{store_name}.myshopify.com/admin/oauth/access_token?client_id={client_id}".format(
store_name=store_name, client_id=client_id
)
request_url += "&client_secret=" + shopify_config['client_secret']
request_url += "&code=" + code
response = requests.post(request_url)
shopify_access_token = response.json()['access_token']
print("shopify_access_token")
print(shopify_access_token)
redirect('success_page_url')
如果我像以下网址一样重定向
https://{store_name}.myshopify.com/admin/auth/login?redirect=oauth/authorize?client_id, access_scope
我得到access_scope丢失错误并被重定向到以下URL:
https://{store_name}.myshopify.com/admin/oauth/authorize?client_id
无法确定缺少accsess_scope param的原因 .
任何shopify专家的帮助将不胜感激 .