1
Shopify API有些奇怪的事情發生,我無法理解我做錯了什麼。ShopifyAPI:產品查找since_id奇怪
我想從Shopify得到的所有的產品,所以我使用下面的代碼清單:
def get_all_products_from_shopify
limit = 250
all_products = Array.new
self.connect_to_store
products = ShopifyAPI::Product.find(:all, :params => {:limit => limit})
all_products = all_products.concat products
puts products.length
while products.length == limit do
since_id = products.last.id
products = ShopifyAPI::Product.find(:all, :params => {:limit => limit, :since_id => since_id})
all_products = all_products.concat products
end
ShopifyAPI::Base.site = nil
return all_products
end
的問題是,我有251個產品Shopify上,但用這種方法我檢索數組具有277個元素的產品。 爲什麼?
另外,如果我這樣做:
products = ShopifyAPI::Product.count
> 251
products = ShopifyAPI::Product.find(:all, :params => {:limit => limit})
products.count
>250
since_id = products.last.id
ShopifyAPI::Product.count(since_id: since_id)
>26
誰能告訴我什麼我做錯了嗎?
感謝, 奧古斯托
您能否提供您的商店網址和API密鑰?這將有助於弄清楚發生了什麼。謝謝! –
謝謝大衛,併爲延誤感到抱歉。在第一個查詢中添加:since_id解決了問題。 – Augusto