【问题标题】:Display a list of products in a custom Shopify app在自定义 Shopify 应用中显示产品列表
【发布时间】:2021-12-18 17:23:14
【问题描述】:

我已将代码更新为以下内容:

@app.route('/products_linking', methods=['GET'])
# @helpers.verify_web_call
def products_linking():
    shop = request.args.get('shop')
    global ACCESS_TOKEN
    if ACCESS_TOKEN:
        url = f'https://{shop}.myshopify.com/admin/api/2021-10/'
        def get_products():
            endpoint = 'products.json'
            r = requests.get(url + endpoint)
            return r.json()
        products = get_products()
        print(products)
        print(shop)
        return render_template('products_linking.html', shop=shop, products=products)

当我在我的应用程序中单击 /products_linking 的链接时,我得到 {'errors': '[API] Invalid API key or access token (unrecognized login or wrong password)'} 产品和商店的 'None'多变的。如果 if ACCESS_TOKEN: 块内的代码正在执行,为什么我会收到无效的访问令牌错误?还有为什么 shop 变量的值返回为 None?

【问题讨论】:

    标签: python json flask python-requests shopify


    【解决方案1】:

    您点击了错误的网址。用于获取产品的 Shopify API 端点是

    https://{shop}.myshopify.com/admin/api/2021-10/products.json

    您还需要在 X-Shopify-Access-Token 标头中包含访问令牌。

    【讨论】:

    • 感谢您的帮助。我已经更新了问题
    • 您没有包含 X-Shopify-Access-Token 标头。它应该是您可以从您的private app settings 获得的密码。
    • 至于shop变量,你是在查询参数中传递的吗?例如,.../products_linking?shop=corpdiskdev
    • 是的,当应用程序最初加载时,我得到这个:shop=corpdiskdev.myshopify.com 包含在一个长字符串中,包括代码、hmac 和主机等内容。抱歉,我对此很陌生,我正在使用我在github.com/garettB/shopify-flask-example/tree/master/src找到的示例
    • 我添加了新路由,但我认为这些路由的身份验证存在问题。其他函数没有注释 @helpers.verify_web_call 装饰器,但是如果我取消注释我添加的函数上的装饰器,我会得到 hmac None data b''
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多