Using SLRequest in iOS 6 with Facebook

自古美人都是妖i 提交于 2019-11-29 15:43:46

问题


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!


回答1:


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

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]);
}



回答2:


if error.code == 6, then this is the error message that will appear if the user has not signed into Facebook from Settings app.



来源:https://stackoverflow.com/questions/12569124/using-slrequest-in-ios-6-with-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!