【发布时间】:2020-05-12 00:20:06
【问题描述】:
我正在构建一个带有 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 个产品作为最大限制,但我需要获得所有产品
【问题讨论】:
-
其他电话对您有用吗?您收到的错误是 auth 错误,key\secret 不正确或者您没有发送 auth 标头。
-
WooCommerce.get('products', {})这行工作正常.. 当我添加这样的参数时会发生此错误WooCommerce.get('products?per_page=50', {}) -
尝试将参数移动到数据对象中,例如:
WooCommerce.get('products', {'per_page': 50}).then(...).catch(...)另外,如果您使用的是 Windows,请尝试使用 Fiddler 或使用 Chrome DevTools 网络选项卡查看请求的外观(或其等效的Firefox) -
我试过这种方式..它带来了这个错误 Object { "code": "woocommerce_rest_authentication_error", "data": Object { "status": 401, }, "message": "Invalid signature - 提供的签名不匹配。", }
-
有没有办法让你记录请求?发送了哪些标头?
标签: javascript php react-native woocommerce woocommerce-rest-api