我必须在 iOS 6.0 中单击按钮才能连接到 facebook。我已将社交和帐户框架添加到我的项目中。我可以签到某个地方,但无法为我在 Facebook 上发布的内容标记 friend 。如何获取 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");
}
}
最佳答案
集成 Facebook 的最佳方式是使用新的 iOS 6 Facebook SDK:
https://developer.apple.com/technologies/ios6/
试试这个好友列表链接:
https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/show-friends/
关于iphone - iOS 6.0 Facebook 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12508312/