【发布时间】:2018-02-06 21:31:56
【问题描述】:
我对本机反应还很陌生,我正在尝试使用 FacePlusPlus API (https://console.faceplusplus.com/documents/5679127) 进行测试。
在这里,我尝试将 'api_key' 放入正文中,但是,我也尝试将其放入标题中。两者都没有奏效。
componentDidMount() {
var url = 'https://api-us.faceplusplus.com/facepp/v3/detect';
return fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
api_key: 'blahblahblah',
api_secret: 'blahblahblah',
})
})
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
data: responseJson,
}, function() {
// do something with new state
});
})
.catch((error) => {
console.error(error);
});
}
在 render() 中,我将 console.log(this.state.data) 放在 data 是一个数组以查看响应,但是我得到的只是
Object {
"error_message": "MISSING_ARGUMENTS: api_key",
}
【问题讨论】:
标签: react-native fetch api-key