Created
April 1, 2014 15:12
-
-
Save altyus/9916182 to your computer and use it in GitHub Desktop.
Facebook Login With ACAccountStore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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); | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i coded same way, always got denied