Question

I am trying to do a yelp query and using OAuth Lib

Here is the code

  NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.yelp.com/v2/search?term=petrol+restaurants&ll=%f,%f&radius_filter=300",coordinate.latitude,coordinate.longitude]];

  OAConsumer *consumer = [[OAConsumer alloc] initWithKey:consumerKey secret:consumerSecret];
  OAToken *token = [[OAToken alloc] initWithKey:tokenUrl secret:tokenSecret];

  id<OASignatureProviding, NSObject> provider = [[OAHMAC_SHA1SignatureProvider alloc] init];
  NSString *realm = nil;

  OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:URL
                                                                 consumer:consumer
                                                                    token:token
                                                                    realm:realm
                                                        signatureProvider:provider];
  [request prepare];

  NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  connection = nil;

The code works perfect if the query has one term , term=petrol e.g But if I add two terms like term=petrol+fuel it starts giving me error {"error": {"text": "Signature was invalid", "id": "INVALID_SIGNATURE", "description": "Invalid signature

What is wrong with this code?

SAMPLE API REQUEST

http://api.yelp.com/v2/search?term=cream+puffs&location=San+Francisco

iTS Contains a + but when i use + it gives me above error

Was it helpful?

Solution

I encoded the String with UTF8 Encoding and now working well

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top