gpt4 book ai didi

javascript - React Native 中的 Woocommerce API per_page 最大限制

转载 作者:行者123 更新时间:2023-12-02 21:59:29 24 4
gpt4 key购买 nike

我正在使用 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, }, "message": "无效签名 - 提供的签名不匹配。",}

如果我编写 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
});

关于javascript - React Native 中的 Woocommerce API per_page 最大限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59917333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com