Shopify 嵌入式应用安装时出现“此地址没有页面”错误

问题描述 投票:0回答:9

我面临一个奇怪的问题,当我第一次在测试商店安装应用程序时,安装很顺利,但在 OAuth 后重新安装后,Shopify 向我显示“此地址没有页面”错误。

我的应用程序提交因此被拒绝。我正在使用 https://github.com/osiset/laravel-shopify 库。

laravel shopify shopify-app
9个回答
15
投票

@Mudasser 已经回答了他自己的问题。您需要从数据库中删除旧商店(第一次安装时),然后再次尝试安装,它将起作用。

如果您正确添加了应用程序已卸载的 webhook,则不会出现此问题。


2
投票

对于那些使用 Ruby on Rails 的人

shopify_app
gem:

我们实际上在那里发现了一个问题 - 这可能会帮助其他人。

在:

ShopifyApp::RequireKnownShop#check_shop_known

.../gems/shopify_app-18.0.2/app/controllers/concerns/shopify_app/require_known_shop.rb:24

我们发现一个问题,基本上gem只是检查数据库中的商店是否可以通过域名找到,如果是,则假设一切正常。 但该应用程序没有安装。 因此,我们需要检查它是否确实可以使用现有令牌连接到 Shopify API - 如果不能,则需要重定向到

/login?shop=...
以便正确安装。 可能
shopify_app
gem 不应该检查令牌是否有效/需要重新生成 - 但如果它确实检查的话那就太好了。


0
投票

是的,正如Paul Odeon在用户卸载应用程序后所说,您需要从数据库中删除您的旧商店信息。

我只想提及如何使用 Laravel 做到这一点。

文档

在此页面上,您可以找到

app/uninstalled
webhook。

当用户安装应用程序时,您应该在第一页上创建 webhook。

Laravel
中是这样的:

    $shop = Auth::user();

    $p = $shop->api()->rest('GET', '/admin/api/2021-07/webhooks.json', []);
    $webhooks = $p['body']['container']['webhooks'];

    if(count($webhooks) === 0){
        $p = $shop->api()->rest('POST', '/admin/api/2021-07/webhooks.json', [
            "webhook" => [
                "topic" => "app/uninstalled",
                "address" => env('APP_URL') . "/api/uninstalled/" . $shop->id,
                "format" => "json"
            ]
        ]);
    }

api.php:

Route::post('/uninstalled/{user_id}', 'WebhookController@uninstallAppWebhook');

控制器:

public function uninstallAppWebhook($userId){
        \DB::table('users')->delete($userId);
    }

0
投票

但是如果是这样的场景,在安装app之前无法创建webhook怎么办 检查这个: https://github.com/osiset/laravel-shopify/issues/1071


0
投票

如果您使用 ruby shopify gem 并且仅在重新安装应用程序的情况下发现此消息,则需要在收到卸载 webhook 后在 shop.shopify_tokenshop.shopify_domain 字段上设置 nil。

就我而言,当用户卸载应用程序时,我使用现已弃用的字段“shop.myshopify_domain”来保存域。

如果用户重新安装(甚至几个月后),请找到旧的 SQL 行并切换行。这样用户就可以找到他以前的数据。


0
投票

我们的销售渠道也发生过这种情况,原因是 shopify 的 “APP_UNINSTALLED” webhook 未正确调用或发生一些延迟,因此 session_token 未清除(您可能在该 webhook 处理程序中执行此操作)。由于使用了过期的令牌,您最终会进入该页面。

我们解决这个问题的方法是从会话存储中检索保存的会话,并使用它来访问任何 Shopify 管理 api,如果失败并出现 401 或 403 错误,那么我们假设它是过期的令牌并清除它。

类似这样的:

app.get("/", async (req, res) => {
  if (typeof req.query.shop !== "string") {
    res.status(500);
    return res.send("No shop provided");
  }

  const shop = Shopify.Utils.sanitizeShop(req.query.shop) || "";
  const sessions = await Shopify.Context.SESSION_STORAGE.findSessionsByShop(shop);

  const { AccessScope } = await import(
  `@shopify/shopify-api/dist/rest-resources/${Shopify.Context.API_VERSION}/index.js`
  );

  const scope = await AccessScope.all({
    session: sessions[0],
  }).catch(async (err) => {
    // We check for the error status code and clear our storage
    if (err.response?.code === 401 || err.response?.code === 403) {
      sessions.forEach((session) => redisClient.del(session.id));
      await AppInstallations.delete(shop);
    }
  });
  const appInstalled = await AppInstallations.includes(shop);

  if (!appInstalled) {
    return redirectToAuth(req, res, app);
  }

  if (Shopify.Context.IS_EMBEDDED_APP && req.query.embedded !== "1") {
    const embeddedUrl = Shopify.Utils.getEmbeddedAppUrl(req);

    return res.redirect(embeddedUrl + req.path);
  }

  return handle(req, res);
)};

const AppInstallations = {
  includes: async function (shopDomain: string) {
    if (Shopify.Context.SESSION_STORAGE.findSessionsByShop) {
      const shopSessions =
        await Shopify.Context.SESSION_STORAGE.findSessionsByShop(shopDomain);
      if (shopSessions.length > 0) {
        for (const session of shopSessions) {
          if (session.accessToken) return true;
        }
      }
    }
    return false;
  },

  delete: async function (shopDomain: string) {
    if (Shopify.Context.SESSION_STORAGE.findSessionsByShop) {
      const shopSessions =
        await Shopify.Context.SESSION_STORAGE.findSessionsByShop(shopDomain);
      if (shopSessions.length > 0) {
        if (Shopify.Context.SESSION_STORAGE.deleteSessions) {
          await Shopify.Context.SESSION_STORAGE.deleteSessions(
            shopSessions.map((session) => session.id)
          );
        }
      }
    }
  },
};

0
投票

我意识到我收到了该错误,因为该应用程序的名称与我之前安装的应用程序的名称相同。

我通过简单地更改应用程序的名称解决了这个问题。

micro-app
micro-app2

一旦安装了

micro-app2
,然后我尝试再次安装
micro-app
,并且工作正常


0
投票

接受的答案对我们不起作用。我们用另一种方式解决了这个问题。

我们发现样板中的

/web/public
目录(运行
npm run build
后)同时包含
index.html
index.php

Nginx 的优先级错误地优先考虑了

index.html
- 删除此解决了问题。


0
投票

在 Laravel 中,当我们从 Shopify 应用商店安装任何应用程序时,它会在我们的用户表中创建一个新商店。如果您使用

Osiset/Laravel
ohmybrew/laravel-Shopify
包,那么您必须先从数据库中 删除 您的商店,或者使用下面的代码创建一个新的 Webhook 以启用
uninstall
功能。

将此代码添加到您的

.env
文件

SHOPIFY_UNINSTALLED=APP_UNINSTALLED
SHOPIFY_UNINSTALLED_ADDRESS=yourdomain.com/webhook/app-uninstalled

此 Webhooks 用于从商店卸载您的应用程序并从数据库中删除您的商店条目。

© www.soinside.com 2019 - 2024. All rights reserved.