Skip to content

Instantly share code, notes, and snippets.

@altyus
Created April 1, 2014 15:12
Show Gist options
  • Save altyus/9916182 to your computer and use it in GitHub Desktop.
Save altyus/9916182 to your computer and use it in GitHub Desktop.
Facebook Login With ACAccountStore
- (void)facebookLoginWithCompletion:(void (^)(NSString *userID, NSString *email, NSString *fullName))completion
{
self.accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{
ACFacebookAppIdKey:FACEBOOKAPPID,
ACFacebookPermissionsKey: @[@"read_stream", @"basic_info"],
ACFacebookAudienceKey:ACFacebookAudienceFriends
};
[self.accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error) {
if (granted)
{
//NSLog(@"Permission Granted");
NSArray *accounts = [self.accountStore accountsWithAccountType:accountType];
ACAccount *account = (ACAccount *)[accounts lastObject];
NSString *userID = [[[account valueForKey:@"properties"] valueForKey:@"uid"] stringValue];
NSString *email = [[account valueForKey:@"properties"] valueForKey:@"ACUIDisplayUsername"];
NSString *fullName = [[account valueForKey:@"properties"] valueForKey:@"ACPropertyFullName"];
completion(userID, email, fullName);
}
else
{
NSLog(@"Permission denied");
NSLog(@"%@", error);
}
}];
}
@pwpgithub
Copy link

i coded same way, always got denied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment