Woocommerce API per_page React Native 的最大限制
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);
我在控制台中得到了这个
对象{
"code": "woocommerce_rest_authentication_error",
"data":对象{
"status": 401,
},
"message": "Invalid signature - provided signature does not match.",
}
如果我写 WooCommerce.get('products', {})
它从 woocommerce API 获得 10 个产品作为最大限制,但我需要获得所有产品
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
希望对您有所帮助
在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: 50})
.then(res => {
this.setState({
data: res,
isLoading: false
});
})
.catch(error => {
console.log(error);
this.setState({
error,
isLoading: true
});
});
这应该有效!
我正在构建一个带有 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);
我在控制台中得到了这个
对象{ "code": "woocommerce_rest_authentication_error", "data":对象{ "status": 401, }, "message": "Invalid signature - provided signature does not match.", }
如果我写 WooCommerce.get('products', {})
它从 woocommerce API 获得 10 个产品作为最大限制,但我需要获得所有产品
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
希望对您有所帮助
在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: 50})
.then(res => {
this.setState({
data: res,
isLoading: false
});
})
.catch(error => {
console.log(error);
this.setState({
error,
isLoading: true
});
});
这应该有效!