如何在shopify应用中创建充实(我的代码出什么问题了?)

时间:2019-03-05 05:34:51

标签: ruby-on-rails ruby shopify shopify-app

目标:履行来自shopify应用的订单。

我有以下代码:

实现控制器:

def fulfill_order_2
    order = ShopifyAPI::Order.find(:order_id) #line 17
    f = ::ShopifyAPI::Fulfillment.new(
      # :order_id => reference_number,
      :order_id => order.id,

      :location_id => location_id,
      :tracking_company => tracking_company,
      :tracking_numbers => "1235",
      :line_items => line_items_hash,
    )
    f.prefix_options = { :order_id => reference_number }
    f.save
  end

路线:

get 'fulfillment/fulfill_order_2'

正视图:

<% @orders.each do |order| %>
      <tr>
        <td><%= order.id %></td>
        <td><%= order.name %></td>
        <td><%= order.total_price %></td>
        <td>
          <% if order.fulfillments.empty? %>
          <%= link_to "Fulfill Order", fulfillment_fulfill_order_2_path(:order_id => order.id, :shop_url => @shop_session.url), :remote => true %>
          <% else %>
            Fulfilled
          <% end %></td>
        <td>
      </tr>
      <%end%>

配置范围:

  config.scope = "read_orders, read_products, write_fulfillments, write_orders"

在我的日志中,我得到:

ActiveResource: UnautorizedAccess, Response Code = 401. Response Message = unauthorized.

FATAL line 17在方法中

问题:我的代码完全错误吗?有什么建议吗?

1 个答案:

答案 0 :(得分:1)

401“ UnauthorizedAccess”响应表明您未正确进行身份验证。开始进行特权请求(如检索订单信息)之前,您首先需要进行某种设置。

请参阅您似乎在这里使用的Shopify Authenticationthe README for the Shopify Ruby Gem

  

对于私有应用,您将需要API_KEY和PASSWORD,否则,您将需要API_KEY和SHARED_SECRET。