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 Build a Photo Browser iPhone App Connecting to an API using OAuth Connecting to Instagram

Anuj Verma
Anuj Verma
11,825 Points

Store access token in SSKeychain

I am attempting to the extra credit and I have the code below

    NSString *password = [SSKeychain passwordForService:@"com.anujverma.Photo-Bombers" account:@"theUserName"];
    self.accessToken = password;

    if (self.accessToken == nil){

        [SimpleAuth authorize:@"instagram" completion:^(NSDictionary *responseObject, NSError *error) {

            NSString *accessToken = responseObject[@"credentials"][@"token"];
            [SSKeychain setPassword:accessToken forService:@"com.anujverma.Photo-Bombers" account:@"theUserName"];

        }];

    }

When I enter in my instagram credentials the authentication view goes away but the photos don't show up. But if I re build the app after seems like the access token worked because the pictures show up. Any help would be appreciated! :)

cc Sam Soffes

1 Answer

Mingyuan Wang
Mingyuan Wang
279 Points

Hey Anuj I think I found the way to solve this problem. There's no need to set an NSString *password to store the SSKeychain method. You just need to first add this line into your appDelegate.m file: [SSKeychain setAccessibilityType:kSecAttrAccessibleWhenUnlocked]; Then in your viewController.m, write [SSKeychain setPassword:instagramToken forService:@"InstagramService" account:@"com.yourapp.keychain"]; // set access token for later use.

Then run your app and everything is supposed to be fine. Good luck!