R 与 API 的面部认知识别连接 - 错误 404
Face cognitive recognition connection with API by R - error 404
我想通过 R 连接 Microsoft Face Recognition API。但是,我遇到了 404 错误。这是我的代码(修改自:
https://www.r-bloggers.com/analyze-face-emotions-with-r/)
library(httr)
library("XML")
#guide from: https://www.r-bloggers.com/analyze-face-emotions-with-r/
faceURL <- 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0'
img.url <- 'https://images.pexels.com/photos/614810/pexels-photo-614810.jpeg?auto=compress&cs=tinysrgb&h=650&w=940'
#from: https://azure.microsoft.com/pl-pl/try/cognitive-services/my-apis/
faceKEY <- 'XXX'
# Define image
mybody = list(url = img.url)
# Request data from Microsoft
faceResponse = POST(
url = faceURL,
content_type('application/json'), add_headers(.headers = c('Ocp-Apim-Subscription-Key' = faceKEY)),
body = mybody,
encode = 'json'
)
# Show request results (if Status=200, request is okay)
faceResponse
#Outcome:
#Response [https://westcentralus.api.cognitive.microsoft.com/face/v1.0]
# Date: 2019-02-15 11:14
# Status: 404
# Content-Type: application/json
# Size: 113 B
#
# { "error": { "code": #"ResourceNotFound", "message": "The requested resource was not found." } }
我应该修正什么才能正确连接人脸识别API?
您收到的错误是 404 ({ "error": { "code": #"ResourceNotFound", "message": "The requested resource was not found." } }
),所以您应该看看您正在执行的请求。
事实上,您在这里尝试调用“https://westcentralus.api.cognitive.microsoft.com/face/v1.0”
这是 API 的根,其中有多种方法,例如 Detect
其中 url 是 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect'
在此处查看有关这些方法的更多详细信息:https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d
我想通过 R 连接 Microsoft Face Recognition API。但是,我遇到了 404 错误。这是我的代码(修改自: https://www.r-bloggers.com/analyze-face-emotions-with-r/)
library(httr)
library("XML")
#guide from: https://www.r-bloggers.com/analyze-face-emotions-with-r/
faceURL <- 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0'
img.url <- 'https://images.pexels.com/photos/614810/pexels-photo-614810.jpeg?auto=compress&cs=tinysrgb&h=650&w=940'
#from: https://azure.microsoft.com/pl-pl/try/cognitive-services/my-apis/
faceKEY <- 'XXX'
# Define image
mybody = list(url = img.url)
# Request data from Microsoft
faceResponse = POST(
url = faceURL,
content_type('application/json'), add_headers(.headers = c('Ocp-Apim-Subscription-Key' = faceKEY)),
body = mybody,
encode = 'json'
)
# Show request results (if Status=200, request is okay)
faceResponse
#Outcome:
#Response [https://westcentralus.api.cognitive.microsoft.com/face/v1.0]
# Date: 2019-02-15 11:14
# Status: 404
# Content-Type: application/json
# Size: 113 B
#
# { "error": { "code": #"ResourceNotFound", "message": "The requested resource was not found." } }
我应该修正什么才能正确连接人脸识别API?
您收到的错误是 404 ({ "error": { "code": #"ResourceNotFound", "message": "The requested resource was not found." } }
),所以您应该看看您正在执行的请求。
事实上,您在这里尝试调用“https://westcentralus.api.cognitive.microsoft.com/face/v1.0”
这是 API 的根,其中有多种方法,例如 Detect
其中 url 是 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect'
在此处查看有关这些方法的更多详细信息:https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d