I am trying to reproduce in R the Microsoft Emotion API program located here. I obtained my API key from Microsoft's website and plugged it into the following code (also from the above linked page:
library(httr)
apiUrl <- 'https://api.projectoxford.ai/emotion/v1.0/recognizeInVideo?outputStyle=perFrame'
key <- '2a0a91c98b57415a....'
urlVideo <- 'https://drive.google.com/file/d/0B5EuiMJDiDhWdWZSUGxvV3lJM0U/view?usp=sharing'
mybody <- list(url = urlVideo)
faceEMO <- httr::POST(
url = apiUrl,
httr::content_type('application/json'),
httr::add_headers(.headers = c('Ocp-Apim-Subscription-Key' = key)),
body = mybody,
encode = 'json'
)
operationLocation <- httr::headers(faceEMO)[["operation-location"]]
The request appears to go through successfully as the "faceEMO" object returns a Response 202 code which according to Microsoft's website means:
The service has accepted the request and will start the process later. In the response, there is a "Operation-Location" header. Client side should further query the operation status from the URL specified in this header.
However, when I open the given URL from the 'operationLocation' object, it says:
{ "error": { "code": "Unauthorized", "message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key." } }
This seems to indicate that my request didn't go through after all.
Not sure why it would say my key is invalid. I tried to regenerate the key and run it again but received the same result. Maybe it has something to do with the fact that Microsoft gives me 2 keys? Do I need to use both?
To add additional info, I also tried running the next few lines of code given from the linked web site:
while(TRUE){
ret <- httr::GET(operationLocation,
httr::add_headers(.headers = c('Ocp-Apim-Subscription-Key' = key)))
con <- httr::content(ret)
if(is.null(con$status)){
warning("Connection Error, retry after 1 minute")
Sys.sleep(60)
} else if (con$status == "Running" | con$status == "Uploading"){
cat(paste0("status ", con$status, "\n"))
cat(paste0("progress ", con$progress, "\n"))
Sys.sleep(60)
} else {
cat(paste0("status ", con$status, "\n"))
break()
}
}
When I run this I'm shown a message indicating "status Running" and "progress 0" for about 30 seconds. Then it shows "status Failed" and stops running without giving any indication of what caused the failure.