首页 > 解决方案 > R:Httr 包 - 与 API 的连接,错误 1200:描述”:“__all__:需要 img 或 url 参数

问题描述

我是 HTTR 的新手,并且通过 R 连接 API。我无法连接 FACE API(文档:https ://face-api.sightcorp.com/dev-documentation/ )

library(httr)
library("XML")
library("jsonlite")
library(RCurl)

key = 'XXX'
img = 'C:\\my_image.jpg'

The query:
my_json <- POST('https://api-face.sightcorp.com/api/detect/', add_headers(app_key = key, img = img, ethnicity = TRUE ))
print(my_json)

和答案:

Response [https://api-face.sightcorp.com/api/detect/]
  Date: 2019-02-19 20:26
  Status: 200
  Content-Type: application/json
  Size: 88 B
{
  "error_code" : 1200,
  "description" : "__all__ : img or url parameter is needed."

如何在代码中实现 img 或 url 地址以获取 API 分析?

标签: rapihttr

解决方案


解决方法如下:

my_body = list('app_key'=key, 'img'= upload_file(img.url))
my_json <- POST('https://api-face.sightcorp.com/api/detect/',body = my_body)

推荐阅读