using iOS SDK with API call requiring access token (OAuth)
  • There are several calls in the API that require passing in an access token. An example in the API docs shows this:
    $ curl \
    -H "Authorization: OAuth 152a5-2c91e9335da92345ef48f7bc45c17272a40abf52" \
    -H "Content-type: application/json" \
    -d '{"push": true, "text": "Hello everyone!"}'

    I'm attempting to translate this for use with the iOS SDK, and there aren't any examples of how to add the access token in the documentation. The closest I've gotten so far (thanks to some code in DinoDeals) is this:
    // send a message to all the users in the group    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];    [params setObject:[NSNumber numberWithBool:true] forKey:@"push"];    [params setObject:@"Hello everyone!" forKey:@"text"];
        NSMutableURLRequest *request = [[[LQSession savedSession] requestWithMethod:@"POST" path:@"/group/message/d6QwhleSy" payload:params] mutableCopy];    [request setValue:[NSString stringWithFormat:@"OAuth %@", [LQSession savedSession].accessToken] forHTTPHeaderField:@"Authorization"];    [[LQSession savedSession] runAPIRequest:request completion:^(NSHTTPURLResponse *response, NSDictionary *responseDictionary, NSError *error) {
            NSLog(@"Response to sending a message to the group: %@ error:%@", responseDictionary, error);    }];
    Is this a proper way to format this call? It seems right, but I'm getting a "You are not authorized..." response, so it's hard to tell. 
  • 2 Comments sorted by
  • Actually the SDK handles this automatically. Here is a simple example of making an API call with the access token:

    When you use the "requestWithMethod" and "runAPIRequest" methods of LQSession, the session class takes care of all the authentication and JSON parsing.

    NSURLRequest *req = [[LQSession savedSession] requestWithMethod:@"GET" path:@"/location/context" payload:nil];
    [[LQSession savedSession] runAPIRequest:req completion:^(NSHTTPURLResponse *response, NSDictionary *responseDictionary, NSError *error) {
      // do stuff
  • Roger that! It's all becoming more clear now.
    Thanks for helping us all wade through the docs and samples. 

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion