Access Facebook Accounts on OS X Mountain Lion

Since Mountain Lion now has a built-in Facebook, I wanted to play a bit with Accounts.frameworkand Social.frameworkOS X.

I installed the application in the application for Facebook developers and used the following code to request access to the registered user’s Facebook accounts:

ACAccountStore *acStore = [[ACAccountStore alloc] init];
ACAccountType *accType = [acStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:FB_APP_ID, ACFacebookAppIdKey, @"read_stream, publish_stream", ACFacebookPermissionsKey, ACFacebookAudienceFriends, ACFacebookAudienceKey, nil];


[acStore requestAccessToAccountsWithType:accType options:options completion:^(BOOL granted, NSError *error) {
    if (granted) {
        NSLog(@"Accounts: %@", acStore.accounts);
        NSLog(@"Access granted");
    } else {
        NSLog(@"Access denied");
    }
}];

Now I always get an error Error Domain=XPCObjectsErrorDomain Code=2 "The operation couldn’t be completed. (XPCObjectsErrorDomain error 2.)"

When I started the application from Xcode for the first 2-3 times, OS X displayed a confirmation dialog box “XYZ wants to access your Facebook accounts,” I clicked ok and I got an error saying something like “The application has not yet was installed. " This error has now “disappeared” and I am getting the error message above.

: - Xcode (Info.plist) Facebook, OS X? - ? : -/

WWDC 2012 Twitter/Facebook, , .

: -)

Cheers,


, ;-) NSArray, . , :

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: FB_APP_ID, ACFacebookAppIdKey, [NSArray arrayWithObjects:@"read_stream", @"publish_stream", @"email", @"user_likes", nil], ACFacebookPermissionsKey, ACFacebookAudienceFriends, ACFacebookAudienceKey, nil];

OS X , , App Facebook , OK , Facebook:

Error Domain=com.apple.accounts Code=7 "The Facebook server could not fulfill this access request: The app must ask for a basic read permission at install time."

email user_likes, . read_stream, , 190 OAuth Error validating access token: User XXXXXX has not authorized application XXXXXX.

2:
, . .

+5
2

, , , : -)

Facebook, , " " Facebook.

, , Facebook, , . , , ! read_stream publish_stream .

, :

self.store = [[ACAccountStore alloc] init];

ACAccountType *accType = [self.store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

NSMutableDictionary *options = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                    FB_APP_ID, ACFacebookAppIdKey,
                                    [NSArray arrayWithObjects:@"email", @"user_about_me", @"user_likes", nil], ACFacebookPermissionsKey, ACFacebookAudienceFriends, ACFacebookAudienceKey, nil];    

[self.store requestAccessToAccountsWithType:accType options:options completion:^(BOOL granted, NSError *error) {
    if (granted && error == nil) {
        self.accounts = self.store.accounts;    
        [options setObject:[NSArray arrayWithObjects:@"read_stream, read_mailbox, read_requests", nil] forKey:ACFacebookPermissionsKey];
        [self.store requestAccessToAccountsWithType:accType options:options completion:^(BOOL granted, NSError *error) {
            if (granted && error == nil) {
                completionHandler(granted, error);
            } else {
                NSLog(@"Access denied 2");
                NSLog(@"%@", [error description]);
            }
        }];
    } else {
        NSLog(@"Error: %@", [error description]);
        NSLog(@"Access denied");
    }
}];

, -: -)

+11

, Facebook :

// if a user has *never* logged into your app, you MUST include one of
// "email", "user_location", or "user_birthday".  Other read 
// permissions can also be included here.

.

+2

All Articles