在iOS 6中使用SLRequest与Facebook [英] Using SLRequest in iOS 6 with Facebook

查看:214
本文介绍了在iOS 6中使用SLRequest与Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SLRequest将状态发布到Facebook这是我的代码:

I'm currently trying to use an SLRequest to post a status on to facebook this is the code i have:

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSLog(@"0");
    [accountStore requestAccessToAccountsWithType:accountType options:@{ACFacebookAppIdKey : @"00000000000", ACFacebookPermissionsKey : @"publish_stream", ACFacebookAudienceKey : ACFacebookAudienceFriends} completion:^(BOOL granted, NSError *error) {
        if(granted) {
            NSLog(@"1");
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
            NSLog(@"2");
            if ([accountsArray count] > 0) {
                NSLog(@"3");
                ACAccount *facebookAccount = [accountsArray objectAtIndex:0];
                NSLog(@"4");
                SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                                requestMethod:SLRequestMethodPOST
                                                                          URL:[NSURL URLWithString:@"https://graph.facebook.com/me/feed"]
                                                                   parameters:[NSDictionary dictionaryWithObject:post forKey:@"message"]];
                NSLog(@"5");

                [facebookRequest setAccount:facebookAccount];
                NSLog(@"6");

                [facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
                    NSLog(@"%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
                }];


            }
        }
    }];

但是,如果(被授予),我不想超过 ){但我不知道为什么我做了不工作。任何帮助将不胜感激!

however the code i have doesn't want to get past if(granted){ but i can't tell why what I've done isn't working. Any help would be appreciated!

推荐答案

在我的情况下,要解决这个问题,我在我的APP的属性中注册Bundle ID在Facebook上。

In my case, to resolve this, I register the Bundle ID in the properties of my APP on facebook.

在Facebook上编辑您的APP,并寻找选择您的应用程序与Facebook集成,并将您的项目的Bundle ID注册到iOS Bundle ID 原生iOS应用程序。

Edit your APP on facebook and look for "Select how your app integrates with Facebook" and register the Bundle ID of your project on "iOS Bundle ID" in "Native iOS App".

如果不是您的情况,请尝试阅读错误消息:

If not your case, try to read the error message:

if(granted) {
    ...
}
else {
    NSLog([NSString stringWithFormat:@"%@", error.localizedDescription]);
}

这篇关于在iOS 6中使用SLRequest与Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆