Based on the solution here I'm posting this answer.
Imagine you have created the URL and it didn't work and you got 401. Then after a little time you realized the error that Opps! The parameters I was passing needed a bracket and you run the code again and you again got 401.
Why is that?
This is because the parameters which are apiKey, Signature and Expire time are the same and you only changed the other parameters with your GET request. However these three parameters are used to authenticate the user so that means the old signature which was generated to deny the permission will deny it again no matter what.
So to fix that I just changed the expire time from 1577922200
to 1577933200
. I could've changed it to anything but the thing is I just need to give something new so that a new signature can be generated. So when I changed it started working.
OTHER POSSIBLE REASON
While making the signature using SHA1
you use NSString *string_to_sign = [NSString stringWithFormat:@"%@:%@:%@:%@",api_key,http_method,route,expires];
as per the documentation. But in order to make CCHmac
you have to pass it two things:
- Key
- Data
and based on the link it is created as
const char *cKey = [api_private_key cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [string_to_sign cStringUsingEncoding:NSASCIIStringEncoding];
So what I was mistaking is that I was using API Key
in cKey
instead of API Private Key
. So I change it as per tutorial said and it worked. Otherwise I was getting 401
not matter what I try.