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

查看:27
本文介绍了使用 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 墙页面中的 html 发现了它.原来,POST 对象的参数被视为附件,因此唯一要做的就是将属性"属性直接添加到 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天全站免登陆