【发布时间】:2020-02-29 12:41:58
【问题描述】:
我正在使用 React-Native 构建一个向用户推荐服装的移动应用程序。我正在使用Imagga's API 来获取衣服的颜色,同时排除背景。我试图通过分析documentation中给出的node.js代码来使用fetch来发出POST请求:
image_file_b64 = "" + image_file_b64
//Extracting the colors from the object
let response = await fetch('https://api.imagga.com/v2/colors', {
method: 'POST',
headers: {
'apiKey': '<PLACEHOLDER>',
'apiSecret': '<PLACEHOLDER>',
'Authorization': '<PLACEHOLDER>',
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
image_base64: image_file_b64,
extract_overall_colors: 0,
})
})
let responseJson = await response.json()
console.log(responseJson)
但是,我收到的唯一输出是(最后一行记录的内容):
Object {
"status": Object {
"text": "Please provide content for processing.",
"type": "error",
},
}
我曾与 Imagga 的某个人合作解决此问题,但他不熟悉 React Native。他建议将内容类型更改为“application/x-www-form-urlencoded”或“application/x-www-form-urlencoded;charset=UTF-8”,但都没有奏效。
我相当有信心问题出在我设置提取的方式上。如果有人熟悉 Imagga API,您能否确定代码中的错误或 Imagga 期望的内容与我给它的内容之间的格式不匹配导致它不认为我已经给它输入了。谢谢!
【问题讨论】:
-
你是在 react-native 还是 node.js 中使用这个 api?
-
@SuleymanSah 我在 react-native 中使用 API
标签: node.js rest react-native fetch-api