Search code examples
razureface-api

Face cognitive recognition connection with API by R - error 404


I want connect with Micrososoft Face Recognition API via R. However, I got and 404 error. Here is my code (modified from: 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." } }

What shall I correct to properly connect with Face Recognition API?


Solution

  • The error you received is a 404 ({ "error": { "code": #"ResourceNotFound", "message": "The requested resource was not found." } }), so you should have a look the request you are doing.

    In fact you are trying here to call 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0'

    This is the root of the API where there are several methods, like Detect which url is 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect'

    See more details about the methods here: https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d