首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在iOS 6和Facebook中使用SLRequest

在iOS 6和Facebook中使用SLRequest
EN

Stack Overflow用户
提问于 2012-09-25 00:27:22
回答 2查看 6.8K关注 0票数 2

我目前正在尝试使用SLRequest将状态发布到facebook上,这是我的代码:

代码语言:javascript
复制
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]);
                }];


            }
        }
    }];

然而,我拥有的代码不想通过if(granted){,但我不知道为什么我所做的事情不起作用。任何帮助都将不胜感激!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-25 02:45:13

在我的例子中,为了解决这个问题,我在facebook上的应用程序的属性中注册了Bundle ID。

在facebook上编辑你的应用程序,查找“选择你的应用程序如何与Facebook集成”,并在“本地iOS应用程序”中的"iOS捆绑包ID“上注册你的项目的捆绑包ID。

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

代码语言:javascript
复制
if(granted) {
    ...
}
else {
    NSLog([NSString stringWithFormat:@"%@", error.localizedDescription]);
}
票数 4
EN

Stack Overflow用户

发布于 2015-09-02 20:11:45

如果是error.code == 6,则这是如果用户没有从设置应用程序登录到Facebook时会出现的错误消息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12569124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档