objective c - WooCommerce iOS OAuth Invalid Signature -
many people have been tearing hair out looking solution invalid signature issue when sending requests woocommerce api ios app.
i have put solution here.
i providing solution invalid signature issue when sending requests woocommerce api ios app.
to use woocommerce in ios app, requests must authenticate using oauth 1.0. in ios, regardless of whether app being written in objective-c or swift, afnetworking makes life easier when writing requests.
follow procedure setup requests:
- get url, oauth 1.0 consumer key , consumer secret ready.
add afnetworking project using cocoapods. podfile this:
source 'https://github.com/cocoapods/specs.git' platform :ios, '9.0' target 'oauthsample3' use_frameworks! # pods oauthsample3 pod 'afnetworking', '1.3.4' end
save in project directory , run
pod install
in terminal.
next step, must install afnetworking 1.3.4. that's why says 1.3.4 in podfile.next, download project github: https://github.com/khanghoang/-wooclient
unzip , copyafoauth1client.h
,afoauth1client.m
,afoauth1oneleggedclient.h
,afoauth1oneleggedclient.m
,afoauth1oneleggedclientwooparser.h
,afoauth1oneleggedclientwooparser.m
project.now need modify these files bit. open
afoauth1client.h
, findafhmacsha1signature()
method.
these lines:// one-legged if(![secret isequaltostring:@""]) { secretstring = [secretstring stringbyappendingformat:@"&%@", afpercentescapedquerystringpairmemberfromstringwithencoding(secret, stringencoding)]; }
and replace them with:
// one-legged secretstring = [secretstring stringbyappendingformat:@"&"];
that's it! solve issue.
in view controller make request this:
- (void)viewdidload { [super viewdidload]; afoauth1oneleggedclient *client = [[afoauth1oneleggedclient alloc] initwithbaseurl:[nsurl urlwithstring:path] key:oauth_consumer_key secret:oauth_consumer_secret]; [client getpath:@"orders" parameters:@{} success:^(afhttprequestoperation *operation, id responseobject) { } failure:^(afhttprequestoperation *operation, nserror *error) { }]; }
you add parameters in dictionary. oauth_consumer_key
, oauth_consumer_secret
must replaced values gathered in first step.
you in swift. use bridging header import afnetworking files.
many khanghoang breakthrough in afoauth1client.
Comments
Post a Comment