iphone - iOS 6.0 Facebook 连接

标签 iphone

我必须在 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/

相关文章:

iphone - 尝试从磁盘访问缓存请求时 NSURLCache 返回 nil

ios - 如何检查 Objective c 中是否没有服务器响应

iPhone : Simple UITableViewController crash without console error nor debugging clue

iphone - 在表格 View 单元格上绘制一条线并将其移动到表格末尾时的 UITableview 可重用性问题

iphone - CALayer setNeedsDisplayInRect - InRect 的意义是什么?或者在drawInContext中更快地绘制

iphone - 了解 Core Data 中的嵌套上下文

iphone - UIWebView contentEditable 图像复制粘贴崩溃 (EXC_BAD_ACCESS)

iphone - UITextField 在 UITableView 中滚动时清除 - 自定义单元格

iphone - 如何实现水波纹?

iphone - UIScrollView 在 UIView (XIB) 之上并且 scrollview 不会滚动