question

EluxsanaSubenderan-7718 avatar image
0 Votes"
EluxsanaSubenderan-7718 asked romungi-MSFT commented

Error with calling Speaker Identification API. When i try to return a profile Id i get a Error: Error Domain=NSURLErrorDomain Code=-1012 "(null)"

The following error message is what i get when i try to return a profile Id for enrolment. I have already tried to see if it is an authentication error by using the API console, everything seems to be returning fine over there. I have provided my implementation/sample code below. Currently I am using the objective c code from the link below as a bridge header for my swift app:

https://westus.dev.cognitive.microsoft.com/docs/services/563309b6778daf02acc0a508/operations/5645c3271984551c84ec6797



This is the error message i receive when i try to return the Profile Id for Enrolment:

"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true 2021-03-23 14:56:16.205386-0400 Reka[50677:760200] Error: Error Domain=NSURLErrorDomain Code=-1012 "(null)" UserInfo={NSErrorFailingURLStringKey=https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true, NSUnderlyingError=0x600002755290 {Error Domain=kCFErrorDomainCFNetwork Code=-1012 "(null)" UserInfo={_kCFURLErrorAuthFailedResponseKey=<NSHTTPURLResponse: 0x600002a746a0> { URL: https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true } { Status Code: 401, Headers { "Content-Length" = ( 225 ); "Content-Type" = ( "application/json" ); Date = ( "Tue, 23 Mar 2021 18:56:15 GMT" ); "Strict-Transport-Security" = ( "max-age=31536000; includeSubDomains; preload" ); "Www-Authenticate" = ( "AzureApiManagementKey realm=\"https://westus.api.cognitive.microsoft.com/spid/v1.0",name="Ocp-Apim-Subscription-Key",type="header""; ); "apim-request-id" = ( "5ab215e6-1efe-4f92-9468-3dc14a79567e" ); "x-content-type-options" = ( nosniff ); } }}}, NSErrorFailingURLKey=https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true}";


Implementation of my code

@implementation PersonIdObject

(int) personIdMethod {
NSLog(@"SomeMethod Ran");

  @autoreleasepool {
   NSString* path = @"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles";
   NSArray* array = @[
                        // Request parameters
                        @"entities=true",
                     ];
        
   NSString* string = [array componentsJoinedByString:@"&"];
   path = [path stringByAppendingFormat:@"?%@", string];
   NSLog(@"%@", path);
   NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
   [_request setHTTPMethod:@"POST"];
   // Request headers
   [_request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
   [_request setValue:@"{subscription key}" forHTTPHeaderField:@"sub_key"];
   // Request body
   [_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
            
   NSURLResponse *response = nil;
   NSError *error = nil;
   NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
   if (nil != error)
   {
       NSLog(@"Error: %@", error);
   }
   else
   {
       NSError* error = nil;
       NSMutableDictionary* json = nil;
       NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
       NSLog(@"%@", dataString);
                
       if (nil != _connectionData)
       {
           json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
       }
                
       if (error || !json)
       {
           NSLog(@"Could not parse loaded json with error:%@", error);
       }
                
       NSLog(@"%@", json);
       _connectionData = nil;
   }
            
   //[pool drain];
   return 0;
   }

}


azure-cognitive-servicesazure-speech
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@EluxsanaSubenderan-7718 I think you are using the sample code of ObJC from the API console. Based on this code the path or URI should contain the Profile ID as below which is missing in your code snippet above:

 NSString* path = @"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/{identificationProfileId}/enroll";



0 Votes 0 ·

@EluxsanaSubenderan-7718 Did you get a chance to review the below comment and check if path is corrected?

0 Votes 0 ·

0 Answers