簡體   English   中英

FbConnect:同時在用戶牆上和新聞源中發布嗎?

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

我正在使用以下代碼使用FbConnect登錄到Fb:

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

}

然后,我使用以下代碼發布到用戶的牆:

- (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不需要使用JSONWriterActionLinks 因此,請嘗試升級您的API並遵循facebook網站提供的facebook教程。

Facebook API教程鏈接: https : //developers.facebook.com/docs/mobile/ios/build/

您也可以嘗試此代碼。 它對我來說很完美。 我正在使用ARC(自動參考計數) 因此,如果您想自己添加它。 不要忘記也將您的APP_ID添加到代碼.plist文件中

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM