使用iPhone SDK使用Facebook Graph API发布附件

时间:2011-04-06 15:08:36

标签: iphone objective-c facebook-graph-api attachment

我一直在拼命地使用Facebook的Graph API发布带有当前用户墙的附件的消息。我已经成功发布了带有图像的POST对象,但是一旦我开始进入附件,它将无法工作。就好像它没有认出那个属性一样。

这是我的代码示例:

NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"ATT NAME", @"name",
                            @"http://my.web.com", @"href",
                            @"ATT CAPTION", @"caption",
                            @"ATT DESC", @"description",
                            [NSDictionary dictionaryWithObjectsAndKeys:
                             @"property 1", @"PROP1",
                             @"property 2", @"PROP2",
                             nil], @"properties"
                            nil];

NSString *attachmentStr = [jsonWriter stringWithObject:attachment];

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"post", @"type",
                               @"MY MESSAGE", @"message",
                               attachmentStr, @"attachment",
                               nil];

[_facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

这将发布“我的消息”,但没有别的。我真正需要这种附件的原因是因为“属性”元素。

提前非常感谢!

编辑:我只是想澄清一下,如果我使用以下字典作为我的参数而不是上面的字典,它的工作原理非常好。我的问题是我需要使用“attachment”对象的“properties”属性进行格式化。这是字典:

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"post", @"type",
                               @"http://my.web.com/pic.png", @"picture",
                               @"http://my.web.com", @"link",
                               postName, @"name",
                               postCaption, @"caption",
                               postDescription, @"description",
                               postMessage, @"message",
                               nil];

2 个答案:

答案 0 :(得分:2)

好的,我找到了如何与我的流帖一起发送属性。我通过查看实际Facebook Wall页面中的html来发现它。事实证明,POST对象的参数被认为是附件,所以唯一要做的就是将“properties”属性直接添加到POST参数中,如下所示:

NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"property 1", @"PROP1",
                            @"property 2", @"PROP2",
                            nil];

NSString *propStr = [jsonWriter stringWithObject:properties];


NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                           @"post", @"type",
                           @"http://my.web.com/pic.png", @"picture",
                           @"http://my.web.com", @"link",
                           postName, @"name",
                           postCaption, @"caption",
                           postDescription, @"description",
                           postMessage, @"message",
                           propStr, @"properties",
                           nil];

[_facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

瞧!它奏效了!

答案 1 :(得分:0)

要发布FEED,您必须使用“USERID / feed”

例如:  [facebook requestWithGraphPath:@“1231241 / feed”
                     andParams:PARAMS
                     andHttpMethod:@ “POST”
                       andDelegate:自];

关于属性,我不认为他们是任何名为“properties”的属性都可用于feed API。

点击此处:http://developers.facebook.com/docs/reference/api/photo/