简体   繁体   中英

FbConnect : Publish on user's wall and in the newsfeed simultaneously?

I am using the following code to login to Fb using FbConnect :

- (IBAction)loginButtonClicked:(id)sender {

    facebook = [[Facebook alloc] initWithAppId:@"355949667779777" andDelegate:self];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }
    if (![facebook isSessionValid]) {
        NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"user_likes", 
                                @"read_stream",
                                @"publish_stream",
                                nil];
        [facebook authorize:permissions];
        [permissions release];
    }

}

Then I use the following code to post to user's wall :

- (IBAction)postToWallPressed:(id)sender {

        SBJSON *jsonWriter = [[SBJSON new] autorelease];

        // The action links to be shown with the post in the feed
        NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                                                      @"Get Started",@"name",@"http://m.facebook.com/apps/hackbookios/",@"link", nil], nil];
        NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
        // Dialog parameters
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       @"Testing VB", @"name",
                                       @"Integrating Facebook in VB.", @"caption",
                                       @"VB is a voice morphing app for videos.", @"description",
                                       @"http://www.google.com/", @"link",
                                       @"http://www.freeimagehosting.net/newuploads/49ncw.png", @"picture",
                                       actionLinksStr, @"actions",
                                       nil];

        [facebook dialog:@"feed" andParams:params andDelegate:self];


}

The post is published fine on the user's wall, but it doesn't get published in the newsfeed.

What am I doing wrong here ?

Link for newly Updated Facebook API: https://github.com/facebook/facebook-ios-sdk

Are you using Updated Facebook API? Because in recently updated facebook API, you dont need to use JSONWriter and ActionLinks at all. So try to upgrade your API and follow the facebook tutorial given by facebook site.

Link for Facebook API tutorial: https://developers.facebook.com/docs/mobile/ios/build/

You may also try this code. It's working perfectly for me. I'm using ARC(Automatic Reference Counting) . So if you want add it yourself. Dont forget to add you APP_ID in code and .plist file too

-(void)buttonPressed:(id)sender{
facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID" andDelegate:self];

 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
            facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
            facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
        }
if (![facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"user_likes", 
                                @"read_stream",
                                @"publish_stream",
                                nil];
    [facebook authorize:permissions];
}else{
[self postWall];
}
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [facebook handleOpenURL:url]; 
}
- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    [self postWall];
}
-(void)postWall{

    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                     @"https://developers.facebook.com/docs/reference/dialogs/",@"link",
                                   @"http://fbrell.com/f8.jpg",@"picture",
                                   @"Facebook Dialogs",@"name",
                                   @"Reference Documentation",@"caption",
                                   @"Using Dialogs to interact with users.",@"description",
                                   @"Facebook Dialogs are so easy!",@"message",
                                   nil];

    [[self facebook] dialog:@"feed" andParams:params andDelegate:self];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM