3

我可以读取 Facebook 朋友的名字、姓氏、生日……但我无法从我的通讯录中读取 Facebook 用户名 ID。

如果 Facebook 详细信息在我手机的通讯录上,则它可以正常读取,但如果来自CardDAV 服务器则不是。

如果我去AddressBook电话/模拟器上,我可以看到用户名......所以它们可用。

我有read_stream, email, read_friendlists, publish_stream,publish_actions权限。

请帮忙...我的想法已经用完了

iOS6、XCode 4.5、Facebook SDK 3.1

// Extract
// These all return values

CFStringRef cfsPrefix       = ABRecordCopyValue((__bridge ABRecordRef)recPerson, kABPersonPrefixProperty);
CFStringRef cfsFirstname    = ABRecordCopyValue((__bridge ABRecordRef)recPerson, kABPersonFirstNameProperty);
CFStringRef cfsLastname     = ABRecordCopyValue((__bridge ABRecordRef)recPerson, kABPersonLastNameProperty);
CFStringRef cfsCompany      = ABRecordCopyValue((__bridge ABRecordRef)recPerson, kABPersonOrganizationProperty);
NSDate*     datBirthday     = (NSDate*) CFBridgingRelease(ABRecordCopyValue((__bridge ABRecordRef)recPerson, kABPersonBirthdayProperty));
NSDate*     datCreate       = (NSDate*) CFBridgingRelease(ABRecordCopyValue((__bridge ABRecordRef)recPerson, kABPersonCreationDateProperty));
NSDate*     datModify       = (NSDate*) CFBridgingRelease(ABRecordCopyValue((__bridge ABRecordRef)recPerson, kABPersonModificationDateProperty));

// This never returns a value in strFacebook

NSString *strFacebook;

ABMultiValueRef socialMulti = ABRecordCopyValue((__bridge ABRecordRef) recPerson, kABPersonSocialProfileProperty);

// ABMultiValueGetCount(socialMulti) always returns 0 ?

for (CFIndex i = 0; i < ABMultiValueGetCount(socialMulti); i++) {
    NSDictionary* social = (__bridge NSDictionary*)ABMultiValueCopyValueAtIndex(socialMulti, i);

    if ([social[@"service"] isEqualToString:(__bridge NSString*)kABPersonSocialProfileServiceFacebook]) {
        strFacebook = (NSString*)social[@"username"];
        NSLog(@"we got a facebook. username is %@ %@", [self nameForSource:(__bridge ABRecordRef)recPerson], cFacebook);
    }
}
4

3 回答 3

1

我正在执行以下操作并且它有效。
我知道这不完全是您正在做的事情,但仍然 - 我的ABMultiValueGetCount工作正常。

ABAddressBookRef addressBook;
addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

NSMutableArray *socialArray = [[NSMutableArray alloc] init];
ABMultiValueRef socialProfiles = ABRecordCopyValue(record, kABPersonSocialProfileProperty);
for (int i=0; i<ABMultiValueGetCount(socialProfiles); i++) {
    NSDictionary *socialItem = (__bridge NSDictionary*)ABMultiValueCopyValueAtIndex(socialProfiles, i);
    [socialArray addObject:socialItem];
}
于 2013-01-16T12:45:28.933 回答
1

您可以获取 facebook IM 并将此名称添加到 www.facebook.com/(fbName)

 ABMultiValueRef profile = ABRecordCopyValue(who,  kABPersonInstantMessageProperty);
if (ABMultiValueGetCount(profile) > 0)
{
    // collect all emails in array

    for (CFIndex i = 0; i < ABMultiValueGetCount(profile); i++)
    {
        NSDictionary *socialItem = (__bridge NSDictionary*)ABMultiValueCopyValueAtIndex(profile, i);
        NSString* SocialLabel =  [socialItem objectForKey:(NSString *)kABPersonInstantMessageServiceKey];

         if([SocialLabel isEqualToString:(NSString *)kABPersonInstantMessageServiceFacebook])
        {

            NSString *facebookProfile = ([socialItem objectForKey:(NSString *)kABPersonInstantMessageUsernameKey]);
            NSLog(@"fbName %@",facebookProfile);
        }

    }
    CFRelease(profile);
}
于 2013-06-01T10:34:43.423 回答
0

如果联系人没有 Facebook 别名,则返回一个空的 NSString ("")。

- (NSString*)facebookAliasForContact:(ABRecordRef)person {
    ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);
    NSString *facebookAlias = @"";

    if (instantMessage) {
        for (NSInteger i=0 ; i < ABMultiValueGetCount(instantMessage); i++) {
            CFDictionaryRef instantMessageValue = ABMultiValueCopyValueAtIndex(instantMessage, i);
            CFStringRef instantMessageString = CFDictionaryGetValue(instantMessageValue, kABPersonSocialProfileUsernameKey);

    if (CFStringCompare(instantMessageString, kABPersonInstantMessageServiceFacebook, 0) == kCFCompareEqualTo) {
            facebookAlias = (__bridge NSString *)instantMessageString;
        }        

    CFRelease(instantMessageString);
            CFRelease(instantMessageValue);
        }
    }

    CFRelease(instantMessage);

    return facebookAlias;
}
于 2014-10-17T20:20:46.930 回答