[英]per_page is not type of integer. Woocommerce REST API Node.js
[英]Woocommerce API per_page max limit in react native
我正在構建一個帶有 react native 和 woocommerce 的電子商務移動應用程序,我正面臨這個問題.. per_page 不起作用
這是代碼
import WooCommerceAPI from 'react-native-woocommerce-api';
const WooCommerce = new WooCommerceAPI({
url: 'http://example.com/', // Your store URL
ssl: false,
consumerKey: 'ck_xxxxxxxxxxx', // Your consumer key
consumerSecret: 'cs_xxxxxxxxxxx', // Your consumer secret
wpAPI: true, // Enable the WP REST API integration
version: 'wc/v3', // WooCommerce WP REST API version
queryStringAuth: true
});
然后
componentDidMount() {
WooCommerce.get('products?per_page=50', {})
.then(res => {
this.setState({
data: res,
isLoading: false
});
})
.catch(error => {
console.log(error);
this.setState({
error,
isLoading: true
});
});
}
進而
console.log(this.state.data);
我在控制台得到了這個
對象{“代碼”:“woocommerce_rest_authentication_error”,“數據”:對象{“狀態”:401,},“消息”:“無效簽名 - 提供的簽名不匹配。”,}
如果我編寫WooCommerce.get('products', {})
它會從 woocommerce API 中獲取 10 個產品作為最大限制,但我需要獲取所有產品
在node_modules\\react-native-woocommerce-api\\lib\\ 中打開react-native-woocommerce-api.js
然后轉到第 195 行(_getOAuth().authorize 函數)並更改:
params.qs = this._getOAuth().authorize({
url: url,
method: method
});
到
params.qs = this._getOAuth().authorize({
url: url + '?' + this.join(data, '&'),
method: method
});
WooCommerce.get('products?per_page=100&page=1', {}) // YOu can set a Variable in-place of 1 and index 100 is the limit
較舊的 API 版本
https://Yoursite/wc-api/v3/products?filter[limit] =-1
希望這可以幫助
WooCommerce.get('products', {per_page: 50})
.then(res => {
this.setState({
data: res,
isLoading: false
});
})
.catch(error => {
console.log(error);
this.setState({
error,
isLoading: true
});
});
這應該工作!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.