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

SimpleAuth problem

I 'm having a problem with the SimpleAuth.

In PhotoBombers app I define instagram client_id and redirect_url in appDelegate.m.

I can't give any response. Instagram modal appears but web page doesn't load in webview.

 SimpleAuth.configuration[@"instagram"] = @{
        @"client_id" : @"68b53361680e4dc5bde0fdbcdf05f75b",
        SimpleAuthRedirectURIKey : @"photobombers://auth/instagram"
    };
[SimpleAuth authorize:@"instagram" completion:^(id responseObject, NSError *error) {
        NSLog(@"Response: %@",responseObject);
        NSLog(@"Error: %@",error);
    }];

1 Answer

  • (void)viewDidLoad { [super viewDidLoad];

        self.title = @"Photo Bombers";
    
        [self.collectionView registerClass:[THPhotoCell class] forCellWithReuseIdentifier:@"photo"];
        self.collectionView.backgroundColor = [UIColor whiteColor];
    
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        self.accessToken = [userDefaults objectForKey:@"accessToken"];
    
        if (self.accessToken == nil) {
            [SimpleAuth authorize:@"instagram" options:@{@"scope": @[@"basic", @"comments", @"likes" , @"relationships"]} completion:^(NSDictionary *responseObject, NSError *error) {
    
                self.accessToken = responseObject[@"credentials"][@"token"];
    
                [userDefaults setObject:self.accessToken forKey:@"accessToken"];
                [userDefaults synchronize];
    
                [self refresh];
            }];
        } else {
    
            [self refresh];
        }
    }
    
    • (void)refresh { NSURLSession *session = [NSURLSession sharedSession]; NSString *urlString = [[NSString alloc] initWithFormat:@"https://api.instagram.com/v1/users/self/media/recent?access_token=%@", self.accessToken];

      NSURL *url = [[NSURL alloc] initWithString:urlString];
      NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
      NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
      
          NSData *data = [[NSData alloc] initWithContentsOfURL:location];
          NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
      
          self.photos = [responseDictionary valueForKeyPath:@"data"];
      
          dispatch_async(dispatch_get_main_queue(), ^{
              [self.collectionView reloadData];
          });
      }];
      [task resume];
      

      }