使用iPhone SDK向Facebook Graph API发布附件 [英] Posting attachments with Facebook Graph API using iPhone SDK

查看:175
本文介绍了使用iPhone SDK向Facebook Graph API发布附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在拼命地使用Facebook的Graph API向当前用户的墙壁发布带有附件的消息。我已经成功地发布一个带有图像的POST对象,但一旦我开始进入附件,它将无法正常工作。这就像是不认识这个财产。

I've been trying desperately to publish a message with an attachment to the current user's wall using Facebook's Graph API. I've been successful at publishing a POST object with an image but once I start getting into attachments, it won't work. It's as if it is not recognizing that property.

这是我的代码示例:

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

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

This will publish "MY MESSAGE" but nothing else. The reason why I truly need this attachment is because of the "properties" element.

非常感谢!

编辑:我只是想澄清一点,如果我使用以下字典作为我的参数,而不是上面的字典,它的工作完全正常。我的问题是我需要使用附件对象的属性属性进行格式化。这是字典:

I just wanted to clarify that if I use the following dictionary for my params instead of the one above, it works perfectly fine. My issue is that I need to use the "properties" property of the "attachment" object for formatting purposes. Here is the dictionary:

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


推荐答案

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

OK, I found how to send properties together with my stream post. I discovered it by taking a look at the html in the actual Facebook Wall page. Turns out, the parameters for the POST object are considered the attachment so the only thing to be done is add the "properties" property directly to the POST parameters like this:

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

瞧瞧!它的工作!

这篇关于使用iPhone SDK向Facebook Graph API发布附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆