2

我必须在 iOS 6.0 中单击按钮连接到 Facebook。我已将框架社交和帐户添加到我的项目中。我可以签到某个地方,但无法为我在 Facebook 上发布的内容标记朋友。如何获取facebook好友列表?

我使用的代码如下所示:

- (IBAction)connectToFacebook:(id)sender
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

NSDictionary *options = @{
@"ACFacebookAppIDKey": @"412590558803147",
@"ACFacebookAppVersionKey": @"1.0",
@"ACFacebookPermissionsKey": @"publish_stream",
@"ACFacebookPermissionGroupKey": @"write"
};

NSLog(@"options is %@",options);

[accountStore requestAccessToAccountsWithType:accountType options:options
                                        completion:^(BOOL granted, NSError *error) {
                                            if (granted)
                                            {
                                                NSArray *accounts = [accountStore
                                                                     accountsWithAccountType:accountType];
                                            NSString *facebookAccount = [accounts lastObject];

                                                NSLog(@"facebook account %@", facebookAccount);
                                            } else {
                                                NSLog(@"%@",error);
                                                // Fail gracefully...
                                            }
                                        }];

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
        if (result == SLComposeViewControllerResultCancelled) {

            NSLog(@"Cancelled");

        } else

        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Posted!!!" message:@"your status is posted to facebook successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alert show];
        }

        [controller dismissViewControllerAnimated:YES completion:Nil];
    };
    controller.completionHandler =myBlock;

    [controller setInitialText:@"This is a ios 6.0 facebook intergration application"];
    [controller addImage:[UIImage imageNamed:@"spalshimage.jpeg"]];

    [self presentViewController:controller animated:YES completion:Nil];

}
else{
    NSLog(@"UnAvailable");
}

}

4

1 回答 1

2

集成 Facebook 的最佳方式是使用新的 iOS 6 Facebook SDK:

https://developer.apple.com/technologies/ios6/

试试这个链接的朋友列表:

https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/show-friends/

于 2012-09-20T08:30:35.120 回答