Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Displaying API Data with Collection Views in Objective-C Show Me the Data - API’s, OAuth, and NSURLSession Parsing a JSON Response

David Lin
David Lin
35,864 Points

Bug in Parsing JSON video: Need to set self.accessToken on first login before calling refreshFoursquare

On first login (when self.accessToken is originally nil), you need to set self.accessToken equal to the newly obtained token before the call to refreshFoursquare. Otherwise, it still won't exist in the subsequent network requests in refreshFoursquare.

    if(self.accessToken == nil){
        [SimpleAuth authorize:@"foursquare-web" completion:^(id responseObject, NSError *error) {
            NSLog(@"response: %@", responseObject);
            NSString *token = responseObject[@"credentials"][@"token"];
            [defaults setObject:token forKey:@"accessToken"];
            [defaults synchronize];

            self.accessToken = token; // *** NEED TO SET TOKEN HERE
            [self refreshFoursquare];
        }];
    } else {
        [self refreshFoursquare];
    }

Note: Other first-time login issues were fixed in this post: Fixing photo flickering and detail view mismatch issues

Roger Antonell
Roger Antonell
18,252 Points

You are right, Thank you

David Lin
David Lin
35,864 Points

Sure thing, Roger.