FbConnect:同时在用户墙上和新闻源中发布吗? [英] FbConnect : Publish on user's wall and in the newsfeed simultaneously?

查看:78
本文介绍了FbConnect:同时在用户墙上和新闻源中发布吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码使用FbConnect登录到Fb:

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


}

帖子在用户的

我在这里做什么错了?

推荐答案

最新更新的Facebook API的链接 https://github.com/facebook/facebook-ios-sdk

您是否正在使用更新的Facebook API?因为在最近更新的facebook API中,您根本不需要使用 JSONWriter ActionLinks 。因此,尝试升级您的API ,并按照Facebook网站提供的Facebook教程进行操作。

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.

Facebook API链接链接: https://developers.facebook.com/docs/mobile/ios/build/

您也可以尝试以下代码。对我来说效果很好。我正在使用 ARC(自动引用计数)。因此,如果您想自己添加它。不要忘记在代码 .plist 文件中也添加您 APP_ID

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

}

这篇关于FbConnect:同时在用户墙上和新闻源中发布吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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