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:

  1. get url, oauth 1.0 consumer key , consumer secret ready.
  2. 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.

  3. next, download project github: https://github.com/khanghoang/-wooclient
    unzip , copy afoauth1client.h, afoauth1client.m, afoauth1oneleggedclient.h, afoauth1oneleggedclient.m, afoauth1oneleggedclientwooparser.h, afoauth1oneleggedclientwooparser.m project.

  4. now need modify these files bit. open afoauth1client.h , find afhmacsha1signature() method.
    these lines:

      // one-legged   if(![secret isequaltostring:@""]) {       secretstring = [secretstring stringbyappendingformat:@"&%@", afpercentescapedquerystringpairmemberfromstringwithencoding(secret, stringencoding)];   }   

    and replace them with:

      // one-legged     secretstring = [secretstring stringbyappendingformat:@"&"];   
  5. 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

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -