2011-01-05 71 views
20

這可能是一個n00b的問題,但毫無疑問...我在我的iPad應用中使用Facebook SDK有點問題:當我使用[facebook dialog:@"feed" andDelegate:self];顯示對話框時,我沒有看到任何方式我可以更改標題,內容或我想分享的網址。Facebook的iOS SDK對話框參數

在他們的演示應用,Facebook有以下代碼:

- (IBAction)publishStream:(id)sender { 

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

    NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary 
    dictionaryWithObjectsAndKeys: @"Always Running",@"text",@"http://itsti.me/", 
           @"href", nil], nil]; 

    NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks]; 
    NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys: 
           @"a long run", @"name", 
           @"The Facebook Running app", @"caption", 
           @"it is fun", @"description", 
           @"http://itsti.me/", @"href", nil]; 
    NSString *attachmentStr = [jsonWriter stringWithObject:attachment]; 
    NSMutableDictionary* params = [NSMutableDictionary 
           dictionaryWithObjectsAndKeys: 
           @"Share on Facebook", @"user_message_prompt", 
           actionLinksStr, @"action_links", 
           attachmentStr, @"attachment", 
           nil]; 


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

} 

然而,當我按下按鈕publishStream,沒有這些字符串顯示在對話框! :S

有什麼我不是做對了嗎?所有我在那個Demo App中改變了Facebook的kAppId和URL Scheme。

回答

19

我有同樣的問題。 這是我找到了解決辦法:改變你的代碼是這樣的:

[_facebook dialog:@"stream.publish" 
     andParams:params 
     andDelegate:self]; 

使用stream.publish和不喂。

+1

真棒,謝謝!你是如何發現你需要stream.publish而不是feed的? – 2011-02-17 17:14:03

+0

嗯。當我嘗試這個時,Facebook對話框返回並聲明「h」是不允許的......無論h是什麼。 :( – 2011-03-18 21:55:29

+2

正如@MrRogers所述,stream.publish API已被棄用,您應該按照他的[正確答案](http://stackoverflow.com/questions/4610153/facebook-ios-sdk-dialog-parameters/6739887#6739887 ) – 2011-08-12 07:35:59

1

嗯..我沒有與示例應用程序一起工作,但我認爲如果你想在牆上張貼東西,你需要做POST。看看這個問題,我的答案在這裏:Post to user's Facebook wall with iPhone using latest FBConnect SDK

總之,這裏是我使用的方法:

- (void)requestWithGraphPath:(NSString *)graphPath 
        andParams:(NSMutableDictionary *)params 
       andHttpMethod:(NSString *)httpMethod 
       andDelegate:(id <FBRequestDelegate>)delegate; 

這樣的:

[_facebook requestWithGraphPath:@"[user_id]/feed" 
          andParams:[NSMutableDictionary dictionaryWithObject:@"test wall post" forKey:@"message"] 
         andHttpMethod:@"POST" 
         andDelegate:self]; 

張貼到[user_id]的牆評論。

+0

問題在於使用'dialog:'不是背景'requestWithGraphPath:'方法。 – Jann 2011-05-25 22:48:15

30

我意識到這已經回答了,但我發現這是正確的答案。它遵循FB有here。圖像和/或鏈接實際上顯示在對話框中。 stream.publish並沒有爲我做出改變。此外,dialog頁面指出stream.publish已過時。

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


[_facebook dialog:@"feed" 
     andParams:params 
     andDelegate:self]; 
+2

這是正確的答案Stream.publish的日期是Feed是正確的,但是這個例子 – Michael 2011-08-03 10:32:31

+2

對話框出現了,但是信息是空的,Docs說'message'字段現在被忽略了:http://developers.facebook.com/docs/reference/dialogs/feed/ – 2011-11-23 13:29:45

+0

愚蠢的是他們沒有更新這個例子,謝謝你的提問 – 2011-12-19 23:25:48