0
-(void)getData:(void (^) (NSArray * result,NSError * error))completion{
NSDictionary * jsonDic;
__block NSString *responsebody = @"";
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"4ff70fabfa83728ca0febe33eaaa7c25"
secret:@"166980cbde6623913b66197458d658f2"];
NSURL *url = [NSURL URLWithString:@"http://ordering.sonitekinternational.com/api/rest/customers/14/addresses"];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
consumer:consumer
token:nil
realm:nil
signatureProvider:nil];
[request prepare];
NSString *oauthHeader = @"OAuth ";
oauthHeader = [oauthHeader stringByAppendingFormat:@"oauth_consumer_key=\"%@\"",@"4ff70fabfa83728ca0febe33eaaa7c25"];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_token=\"%@\"",@"ac42663555d64e1707b109b100240842"];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_signature_method=\"%@\"",@"HMAC-SHA1"];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_signature=\"%@\"",[self encodeToPercentEscapeString:request.signature]];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_timestamp=\"%ld\"", (time_t) [[NSDate date] timeIntervalSince1970]];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_nonce=\"%@\"",request.nonce];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_version=\"1.0\""];
oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_token_secret=\"%@\"",@"04b9f08ffd1fe00b5bda0241c2705ecb"];
[request setValue:oauthHeader forHTTPHeaderField:@"Authorization"];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"GET"];
NSLog(@"Complete url is ==>>%@",request.URL);
NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession]
dataTaskWithRequest:request completionHandler:^(NSData *_Nullable data, NSURLResponse * _Nullable response, NSError *_Nullable error)
{
// Use the data here
if(data == nil){
completion(nil,error);
return;
}
else{
NSHTTPURLResponse *newResp = (NSHTTPURLResponse*)response;
NSLog(@"%ld", (long)newResp.statusCode);
NSMutableArray *parsedObject;
parsedObject=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"Parsed Data ===>>>%@",parsedObject);
}
}];
[dataTask resume];
}
错误在这段代码中我使用我试图通过的obj c中使用OAuth认证来获得数据,但evertime我得到的“oauth_problem = signature_invalid”
import "OAMutableURLRequest.h"
import "OAConsumer.h"
当打印我得到的解析数据**
Parsed Data ===>>>{
messages = {
error = (
{
code = 401;
message = "oauth_problem=signature_invalid";
}
);
};
}
任何人都可以帮助我吗?当我查看http响应代码时,我得到了401,我已经向服务提供商提供了有关意外401响应的信息。
与此同时,对于我可能做错了什么,有什么突出的吗?
即使只是指着我的一些工作示例代码,将不胜感激。我已经阅读了很多东西,但我显然在obj-c中出现了一些错误。
这个键是有效的吗? OAConsumer * consumer = [[OAConsumer alloc] initWithKey:@“4ff70fabfa83728ca0febe33eaaa7c25” secret:@“166980cbde6623913b66197458d658f2”]; – Sofeda
是的,我检查这些键是有效的,但我不知道到底是什么问题。 – Mayank