Facebook iOS SDK对话框参数

20

这可能是一个新手问题,但仍然... 我在我的iPad应用中使用Facebook SDK时遇到了一些问题:当我使用[facebook dialog:@"feed" andDelegate:self];来显示对话框时,我看不到任何可以更改我想要分享的标题、内容或URL的方法。

在他们的演示应用中,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

我做错了什么吗?我在演示应用程序中所更改的只有Facebook kAppId和URL Scheme。

3个回答

30

我意识到这个问题已经有了答案,但是我发现这才是正确的答案。它遵循了FB在这里的说明。在对话框中,图像和/或链接实际上会显示出来。对于我而言,stream.publish无法实现这一点。此外,对话框页面说,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 T
2
对话框弹出,但消息为空。文档表示“消息”字段现在被忽略了:http://developers.facebook.com/docs/reference/dialogs/feed/ - Pavel Alexeev
很傻他們不更新那個例子。謝謝你提醒。 - Mr Rogers
@MrRogers,我有一个相关(但不完全相同)的问题,我认为你可能知道答案。您介意看一下http://stackoverflow.com/questions/11993457/posting-to-facebook-feed-from-iphone-what-do-i-need-to-instantiate-for-this-to? - Joel Derfner
我可以使用UIImage代替HTTP URL来显示图片吗? - Rajavanya Subramaniyan
@Quakeboy,不行。我的理解是你需要单独发布图片。你可以查看http://stackoverflow.com/a/11501388/3965。 - Mr Rogers

19

我曾经遇到过同样的问题。这是我找到的解决方案:以这种方式更改您的代码:

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

使用stream.publish而不是feed。


1
太棒了,谢谢!你是怎么发现需要使用stream.publish而不是feed的呢? - The WebMacheter
哎呀,当我尝试这个的时候,Facebook对话框弹回来说“h”不被允许……无论“h”是什么。:( - Joe D'Andrea
2
正如@MrRogers所指出的那样,stream.publish API已被弃用。您应该遵循他的正确答案 - Nathan de Vries
@dbfranz:这个已经过时了,不再起作用。请遵循Mr Rogers的答案。 - Raptor

1

嗯...我没有使用过这个示例应用程序,但我认为如果你想要发布一些内容到墙上,你需要进行POST操作。请查看这里的问题和我的答案:使用最新的FBConnect SDK在iPhone上发布到用户的Facebook墙上

总结一下,这是我使用的方法:

- (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] 的墙上发表评论。


问题是使用dialog: 而不是背景的requestWithGraphPath: 方法。 - Jann

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接