【问题标题】:Using SLRequest in iOS 6 with Facebook在 iOS 6 中与 Facebook 一起使用 SLRequest
【发布时间】:2012-09-16 03:42:20
【问题描述】:

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

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){,但我不知道为什么我所做的事情不起作用。任何帮助将不胜感激!

【问题讨论】:

    标签: iphone objective-c facebook acaccount social-framework


    【解决方案1】:

    就我而言,为了解决这个问题,我在 facebook 上我的 APP 的属性中注册了 Bundle ID。

    在 facebook 上编辑您的 APP 并查找“选择您的应用如何与 Facebook 集成”并在“Native iOS App”中的“iOS Bundle ID”上注册您项目的 Bundle ID。

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

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

    【讨论】:

    • 干杯!看来我没有正确设置它的 facebook 方面感谢您的帮助。
    • @Yudmt 我已经设置了。但仍然无法正常工作。“iPhone App Store ID”“Facebook 登录”等其他选项呢?都是mendetory ??
    【解决方案2】:

    如果 error.code == 6,则如果用户尚未从“设置”应用登录 Facebook,则会出现此错误消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      • 2013-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多