【问题标题】:Cannot Access themes.json using shopify api and nodejs无法使用 shopify api 和 nodejs 访问 theme.json
【发布时间】:2019-06-14 04:33:46
【问题描述】:

我无法使用 shopify api 和 nodejs 访问我的开发商店的 Themes.json。 这是我正在做的事情:

app.get('/shopify/examplePage', (req, res) => {
  const { shop, hmac, code, state } = req.query;
  const stateCookie = cookie.parse(req.headers.cookie).state;

  // Verifying Cookie
  if (state !== stateCookie) {
    return res.status(403).send('Request origin cannot be verified');
  }

  // Verifying Hmac
  if (shop && hmac && code) {
    const map = Object.assign({}, req.query);
    delete map['hmac'];
    const message = querystring.stringify(map);
    const generatedHash = crypto
      .createHmac('sha256', apiSecret)
      .update(message)
      .digest('hex');

    if(generatedHash !== hmac){
      return res.status(400).send('HMAC verification failed');
    }

    // Appending Access Token to the shop Url
    const accessTokenRequestUrl = 'https://' + shop + '/admin/oauth/access_token';
    const accessTokenPayload = {
        client_id: apiKey,
        client_secret: apiSecret,
        code
    };

    // Making an API Request And getting an API response
    request.post(accessTokenRequestUrl, {json: accessTokenPayload })
    // Promise for Access Token Response
      .then((accessTokenResponse) => {
        const accessToken = accessTokenResponse.access_token;
        // Request URL for Products
        const apiRequestUrl = 'https://' + shop + '/admin/api/2019-04/themes.json'
        console.log(apiRequestUrl);
        const apiRequestHeader = {
            'X-Shopify-Access-Token': accessToken
        };

        request.get(apiRequestUrl, { headers: apiRequestHeader })
        .then((apiResponse) => {
            let example = JSON.parse(apiResponse);
            res.send(example);
          // End API Response
          res.end(apiResponse)
        }).catch((error) => {
          res.status(error.statusCode).send(error.error.error_descripton)
        });
    }).catch((error) => {
      res.status(error.statusCode).send(error.error.error_descripton)
    })
  } else {
    res.status(400).send('Required parameters missing');
  }
});

这个错误表明访问 {ngrok}.ngrok.io 被拒绝,而我可以在相同代码的帮助下访问 product.json 和 shop.json

【问题讨论】:

    标签: api shopify


    【解决方案1】:

    拒绝意味着您的 API 密钥无权访问。如果这是一个公共应用程序,您需要将 read_themes 添加到您的范围。如果它是私人应用程序,您需要转到应用程序设置并添加主题访问权限。

    【讨论】:

      猜你喜欢
      • 2018-09-30
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 2016-06-26
      • 2018-04-27
      • 2013-12-29
      • 1970-01-01
      • 2021-08-19
      相关资源
      最近更新 更多