vish
vish

Reputation: 2436

Facebook social profile in iOS6 address book

I am trying to access contacts' Facebook ID via the address book API in iOS. The code works for profiles that I have manually entered into contacts, but it does not return the social profiles of Facebook accounts that have synced automatically (in iOS6). FYI, it does return the name, email, and phone numbers from the synced contacts. Is there a way to get the Facebook IDs of contacts retrieved from Facebook?

Here is the code I am using:

ABMultiValueRef profiles = ABRecordCopyValue(record_, kABPersonSocialProfileProperty);
CFIndex multiCount = ABMultiValueGetCount(profiles);
for (CFIndex i=0; i<multiCount; i++) {
    NSDictionary* profile = (__bridge NSDictionary*)ABMultiValueCopyValueAtIndex(profiles, i);
    NSLog(@"Profile: %@", profile);
}
CFRelease(profiles);

Upvotes: 3

Views: 955

Answers (2)

Aardvark
Aardvark

Reputation: 598

kABPersonSocialProfileProperty returns limited information unless the user actually manually clicks Settings icon, Facebook icon then allows the facebook app to sync details first on their iOS device. Once this happens you can get all the kABPersonSocialProfileProperty parameters in a linked contact incerted by app in the address book.

See my self answered question:

ABMultiValueGetCount - kABPersonSocialProfileProperty always returns 0 ? How can I get Facebook details from address book?

Upvotes: 0

Ayush Goel
Ayush Goel

Reputation: 3154

I tried your code on my Contacts list, but it doesn't give FB-ID for either the synced or the explicitly added contacts. This is the information i could get for the explicitly added contact with a Facebook profile.

2012-10-29 13:18:06.315 Contacts[6208:907] Profile: { service = facebook; url = "http://www.facebook.com/????"; username = ????; }

(Sorry, can't post images)

Right now, I am using the graph API to get the userID like this:

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@", [(__bridge NSDictionary *)ABMultiValueCopyValueAtIndex(rec, 0) objectForKey:@"username"]]]];
if (data) {
  NSError *error = nil;
  tContact.fbDetails = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
  tContact.fbID = [tContact.fbDetails objectForKey:@"id"];
}
NSLog(@"fbID:%@ fbDetails:%@", tContact.fbID, tContact.fbDetails);

Would still like to see if anyone has any approach to get the FB-ID from Contacts.app itself.

Upvotes: 4

Related Questions