Is it possible to use the built-in iOS 6 Facebook integration to get the user's basic info (email address, birthday, etc)? All of the documentation/examples I have seen use the iOS 6 integration to simply open an SLComposeViewController
.
Thank you for your time.
It's easy, but remember you need to set up your mobile phone for internet and activate your Apple ID on your mobile phone before you can download and install Facebook. Tap Settings. Tap Facebook. Tap INSTALL.
This app lets you manage your account from an Apple device easily. You can connect, upload pics, join groups, and much more with a couple taps of the screen.
Please check out my sample project. It allows you to upload video to Facebook, but it also includes a method to get your info, you should look at the file ViewController.m
, the one noted "Native" in the tab controller.
https://bitbucket.org/danielphillips/fb-video-upload
You will need to import the Social
and Accounts
frameworks to do what you want. You request access to the users Facebook account from the ACAccountStore
, if you are granted access, then you use this account to create an SLRequest
with the parameters you want, here you want the graph object "/me".
Properties:
@property (nonatomic, retain) ACAccountStore *accountStore;
@property (nonatomic, retain) ACAccount *facebookAccount;
Authenticate:
- (IBAction)getMeButtonTapped:(id)sender {
if(!_accountStore)
_accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[_accountStore requestAccessToAccountsWithType:facebookTypeAccount
options:@{ACFacebookAppIdKey: @"483616868329082", ACFacebookPermissionsKey: @[@"email"]}
completion:^(BOOL granted, NSError *error) {
if(granted){
NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
_facebookAccount = [accounts lastObject];
NSLog(@"Success");
[self me];
}else{
// ouch
NSLog(@"Fail");
NSLog(@"Error: %@", error);
}
}];
}
Get "me":
- (void)me{
NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:meurl
parameters:nil];
merequest.account = _facebookAccount;
[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"%@", meDataString);
}];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With