1

I need to show Garmin health data in my app. Garmin documentation ask developer to implement connection thorough oauth 1.0 connection with the app and garmin account. So, when i apply GET/PUSH request with the https://connectapi.garmin.com/oauth-service/oauth/request_token? url, its shows the following error. Fortunately , i am getting proper response in the postman.

Step 1 :

Postman request :

https://connectapi.garmin.com/oauth-service/oauth/request_token?oauth_consumer_key=3f58949f-e54d-4211-a735-e52cc0ab8f4d&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1531983278&oauth_nonce=cW1Xhs&oauth_version=1.0&oauth_signature=WveKS0cnl7w4ZNknL0WD4f7wBFU=

Response :

oauth_token=48d03142-ffe3-4adc-ae0e-6c3d7bdd1e18&oauth_token_secret=EY67QDeBqHNvCzlCt0HU5yQ1LkVkGOMK0b4

In my Code , I apply both GET/POST request, it shows following error :

Garmin Connect API Server - Error report

HTTP Status 400 - Inadequate OAuth consumer credentials.

type Status report

message Inadequate OAuth consumer credentials.

description The request sent by the client was syntactically incorrect.

Garmin Connect API Server

My code is like :

   NSError *error;
NSString *urlString = @"https://connectapi.garmin.com/oauth-service/oauth/request_token?";
NSURL *url = [NSURL URLWithString:urlString];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

NSString * parameterString = [NSString stringWithFormat:@"oauth_consumer_key=3f58949f-e54d-4211-a735-e52cc0ab8f4d&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1531983278&oauth_nonce=cW1Xhs&oauth_version=1.0&oauth_signature=pfZzKhniC9zCFZdIx8d0gyIsw3Y"];
//3f58949f-e54d-4211-a735-e52cc0ab8f4d

 // NSLog(@"%@",parameterString);

[request setHTTPMethod:@"GET"];

[request setURL:url];

[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
   //Even i apply push and set this data, nothing works!
  //    [request addValue:@"3f58949f-e54d-4211-a735-e52cc0ab8f4d" forHTTPHeaderField:@"oauth_consumer_key"];
   //    [request addValue:@"HMAC-SHA1" forHTTPHeaderField:@"oauth_signature_method"];
    //    [request addValue:@"1531983278" forHTTPHeaderField:@"oauth_timestamp"];
   //    [request addValue:@"cW1Xhs" forHTTPHeaderField:@"oauth_nonce"];
   //    [request addValue:@"1.0" forHTTPHeaderField:@"oauth_version"];
  //    [request addValue:@"pfZzKhniC9zCFZdIx8d0gyIsw3Y" forHTTPHeaderField:@"oauth_signature"];
  // [request addValue:@"" forHTTPHeaderField:@"oauth_consumer_key"];


NSData *postData = [parameterString dataUsingEncoding:NSUTF8StringEncoding];

[request setHTTPBody:postData];

NSData *finalDataToDisplay = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];

NSMutableDictionary *abc = [NSJSONSerialization JSONObjectWithData: finalDataToDisplay
                                                           options: NSJSONReadingMutableContainers

                                                             error: &error];

How i can overcome this response issue ? Does anyone face similar issue ? Any idea to make work oauth 1.0 authentication in iOS Swift/Objective Project successfully ?

Jamshed Alam
  • 12,424
  • 5
  • 26
  • 49

0 Answers0