2012-03-30 58 views
1

我使用下面的代碼登錄使用FbConnect到FB: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]; 
    } 

} 

然後我用下面的代碼發佈到用戶的牆:

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


} 

該帖子的發佈用戶的牆罰款,但它不會在新聞源中發佈。

我在這裏做錯了什麼?

回答

1

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

您正在使用Facebook的更新API?因爲在最近更新的Facebook API中,您根本不需要使用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]; 

} 
+0

@「http://fbrell.com/f8.jpg」 ==>我們不能在這裏使用當地的形象? – 2012-05-03 13:11:40

+0

我認爲我們不能..但是即使讓我們嘗試獲取本地圖像的網址,並使用該網址,而不是那個。可能會工作..檢查後,通知我.. – 2012-05-03 13:45:12

相關問題