ios - Can I use RestKit 0.20.3 to submit a request with OAuth parameters required by Yelp? -
i writing ios app requests data yelp.
i have code manages yelp requests/responses , parses json data returned internally. current code builds oauth parameters requests using oauthconsumer jon crosby.
i came upon restkit yesterday, , found appealing. eliminate of request submission , response parsing doing.
but hit roadblock, because have not been able figure out how generate oauth parameters yelp requires restkit. worked through ray wenderlich restkit tutorial @ http://www.raywenderlich.com/13097/intro-to-restkit-tutorial, uses client id , client secret (as required foursquare).
yelp requests need have consumer key, token, signature method, signature, timestamp , nonce. have been unable find add-on restkit can generate particular set of oauth parameters.
i generating restkit requests using afoauth1client developed matt thompson. yelp api returning invalid signature error when send request.
i puzzled because have checked fields in http authorization header, , correct. error seems indicate yelp wants oauth parameters in url, api documentation says acceptable send them in authorization header.
here invalid signature error i'm getting:
2013-08-26 15:34:54.806 restkityelpgroupon[2157:400b] e restkit.network:rkobjectrequestoperation.m:575 object request failed: underlying http request operation failed error: error domain=org.restkit.restkit.errordomain code=-1011 "expected status code in (200-299), got 400" userinfo=0xa876190 {nslocalizedrecoverysuggestion={"error": {"text": "signature invalid", "id": "invalid_signature", "description": "invalid signature. expected signature base string: get\u0026http%3a%2f%2fapi.yelp.com%2fv2%2fsearch\u0026ll%3d32.893282%252c-117.195083%26oauth_consumer_key%3d(my consumer key)%26oauth_nonce%3dc0f25d91-b473-4059-b5f6-2d850a144a1d%26oauth_signature_method%3dhmac-sha1%26oauth_timestamp%3d1377556409%26oauth_token%3d(my oauth token)%26oauth_version%3d1.0%26term%3dsushi"}}, afnetworkingoperationfailingurlrequesterrorkey=http://api.yelp.com/v2/search?ll=32.893282%2c-117.195083&term=sushi>, nserrorfailingurlkey=http://api.yelp.com/v2/search?ll=32.893282%2c-117.195083&term=sushi, nslocalizeddescription=expected status code in (200-299), got 400, afnetworkingoperationfailingurlresponseerrorkey=}
here code using generate requests:
nsurl *baseurl = [nsurl urlwithstring:@"http://api.yelp.com/v2"]; afoauth1client *oauth1client = [[afoauth1client alloc] initwithbaseurl:baseurl key:consumerkey secret:consumersecret]; oauth1client.accesstoken = [[afoauth1token alloc] initwithkey:tokenkey secret:tokensecret session:nil expiration:[nsdate distantfuture] renewable:no]; [oauth1client registerhttpoperationclass:[afjsonrequestoperation class]]; // accept http header; see http://www.w3.org/protocols/rfc2616/rfc2616-sec14.html#sec14.1 [oauth1client setdefaultheader:@"accept" value:@"application/json"]; rkobjectmanager *objectmanager = [[rkobjectmanager alloc] initwithhttpclient:oauth1client]; rkobjectmapping *couponmapping = [rkobjectmapping mappingforclass:[coupon class]]; [couponmapping addattributemappingsfromdictionary:@{@"id" : @"id"}]; rkobjectmapping *businessmapping = [rkobjectmapping mappingforclass:[business class]]; [businessmapping addattributemappingsfromdictionary:@{@"name" : @"name"}]; [businessmapping addpropertymapping:[rkrelationshipmapping relationshipmappingfromkeypath:@"deals" tokeypath:@"location" withmapping:couponmapping]]; rkresponsedescriptor * responsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:businessmapping method:rkrequestmethodget pathpattern:nil keypath:@"response.venues" statuscodes:rkstatuscodeindexsetforclass(rkstatuscodeclasssuccessful)]; [objectmanager addresponsedescriptor:responsedescriptor]; [objectmanager getobjectsatpath:@"http://api.yelp.com/v2/search" parameters:queryparams success:^(rkobjectrequestoperation * operaton, rkmappingresult *mappingresult)
any further assistance appreciated!
take @ using afoauth2client , setting client when init
rkobjectmanager
.
Comments
Post a Comment