首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用shopify-api-node访问Shopify产品时出现问题

使用shopify-api-node访问Shopify产品时出现问题
EN

Stack Overflow用户
提问于 2021-08-07 22:01:32
回答 1查看 102关注 0票数 1

我试图使用shopify-api-node模块访问我的私有Shopify应用程序中的产品,但我收到了一个403错误。

这是我在另一篇Stackoverflow文章的帮助下写的代码:

代码语言:javascript
复制
const express = require('express');
const path = require('path');
const Shopify = require('shopify-api-node');
const https = require('https');
const fetch = require('node-fetch');

const {request, gql, GraphQLClient} = require('graphql-request');

const app = express();
const port = 3000;



const apikey = "*";
const apipassword = "*";
const endpoint = "https://<store>.myshopify.com/admin/api/2021-07/graphql.json"


const shopify = new Shopify({
    shopName: '<store>.myshopify.com',
    apiKey: '*',
    password: '*',
    autoLimit: true
});

app.set('view-engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));


app.get('/', function(req, res) {
    res.render(path.join(__dirname, '/views/index.ejs'));
    shopify.product.count()
    .then(async (count) => {
        if (count > 0) {

            const pages = Math.ceil(count / 250);
            let products = [];

            for (i = 0; i < pages; i++) {
                // use Promise.all instead of waiting for each response
                const result = await shopify.product.list({
                    limit: 250,
                    page: i + 1,
                    fields: 'id, variants'
                });
                products = products.concat(result);
            }
            // products array should have all the products. Includes id and variants
            console.log(products);
        }
    })
    .catch(err => {
        console.log(err);
    });
})

app.get('/treasures', function(req, res) {
    res.render(path.join(__dirname, '/views/treasure.ejs'));
});

app.get('/poetry_books', (req, res) => {

    res.send('Hello World');
});

app.listen(port);

如果有人能告诉我我做错了什么,或者提出了一个更好的方法,那就太棒了。

EN

回答 1

Stack Overflow用户

发布于 2021-11-10 23:25:45

我认为你不能再使用page参数了。试着这样做吧:

代码语言:javascript
复制
let last_id = 0;
do {
    const results = await ShopifyAPI.product.list({
      limit: 250,
      since_id: last_id,
    });

    // Do something with your product data

    last_id = (results.length === 250 ? results[results.length - 1].id : 0);
} while (last_id);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68696431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档