I’m trying to get an image sitting at a URL that is protected by OAuth. I’ve looked through the spec docs but can’t seem to get everything right. Here’s what I’m doing:
Construct an OAuth Authorization header:
NSString *oauthHeader = @"Authorization: OAuth ";
oauthHeader = [oauthHeader stringByAppendingFormat:@"oauth_consumer_key=%@",oauthConsumerKey];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_token=%@",oauthAccessToken];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_signature_method=HMAC-SHA1"];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_signature=%@",escapedString];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_timestamp=%d",oauthTimeStamp];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_nonce=%@",oauthNonce];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_version=1.0"];
Add the Authorization to the http request:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:imageUrl]];
[request setValue:oauthHeader forHTTPHeaderField:@"Authorization"];
And then send it on.
I get an empty response back with a 404 code. I am certain the URL is correct, because as a test if I disable the OAuth protection on the URL I am able to retrieve it fine.
Does anything stick out to you as me doing something wrong? Thanks much.
All OAuth parameters look good, but your code is far from being complete. A wild guess would be that the service provider does not understand the Authorization HTTP header or that you failed to create a valid OAuth signature (in that case try maybe PLAINTEXT).
In each case: replying with a 404 is definitely an error and you should contact the OAuth provider, giving as much detail as you can.