【问题标题】:Shopify :: ActiveResource::ForbiddenAccess: Failed. Response code = 403. Response message = ForbiddenShopify :: ActiveResource::ForbiddenAccess:失败。响应代码 = 403。响应消息 = 禁止
【发布时间】:2017-11-21 09:50:23
【问题描述】:

我已将应用程序(尚未列出)发送给审核。审阅者在 HomeController 的索引操作上收到上述错误,当用户单击安装按钮时触发。我在不同合作伙伴帐户中的许多开发商店验证了该应用程序。我能够为我测试的所有商店成功安装该应用程序。

这里是简化版的代码

controllers/shopify/home_controller.rb

module Shopify
  class HomeController < ShopifyApp::AuthenticatedController
    def index
      MyCustomServie.new(shopify_detail).call
    end

    private

    def current_shopify_store
      @current_shop ||= begin
        Shopify::Base.with_rate_limit_protection do
          ShopifyAPI::Shop.current
        end
      end
    end

    def shopify_detail
      @shopify_detail ||= ShopifyDetail.find_by(shopify_domain: current_shopify_store.try(:myshopify_domain))
    end
  end
end

config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :shopify,
    ShopifyApp.configuration.api_key,
    ShopifyApp.configuration.secret,
    scope: ShopifyApp.configuration.scope,
    callback_path: "#{Settings.shopify.mounted_at}/auth/shopify/callback"

  provider :google_oauth2,
           Settings.google.client_id,
           Settings.google.client_secret,
          { access_type: "offline", approval_prompt: "" }
end

config/initializers/shopify_app.rb

ShopifyApp.configure do |config|
  config.application_name = 'Shopify - Feed Champion'
  config.api_key = Settings.shopify.api_key
  config.secret = Settings.shopify.api_secret
  config.scope = Settings.shopify.scope
  config.embedded_app = true
  config.after_authenticate_job = { job: ShopifyAfterAuthenticateJob, inline: true }
  config.webhooks = [  Shopify::AppUninstalledWebhook::PARAMS  ]
end

错误来自以下行 ShopifyAPI::Shop.current

这里是error log。谁能指点一下哪里有问题?

【问题讨论】:

  • 我不是 Shopify 专家。我一直在学习后端 HTTP API 是无状态的。因此,对于每个请求,您都需要将身份验证令牌传递给 api,如果需要身份验证来执行该request。也许在您的请求中您没有传递正确的身份验证令牌?
  • 同意,但其他人也应该面临同样的问题。问题是我们无法重现问题。
  • 请到直播店确认
  • 我也试过现场直播。那里我也无法复制。

标签: ruby-on-rails shopify-app


【解决方案1】:

作为 Shopify 的新手,我错过了添加使用可用 Shopify API 所需的范围,并且遇到了相同的 ForbiddenAccess 错误。 在shopify_app.rb 中,我添加了缺失的范围。获取 Shopify 商店的所有产品和客户的示例:

config.scope = "read_products, read_customers"

Here 是所有可用范围的列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    相关资源
    最近更新 更多