Posting attachments with Facebook Graph API using iPhone SDK

Deadly 提交于 2019-12-18 18:23:14

问题


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.

Here is my code sample:

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.

Thanks so much in advance!

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

回答1:


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

And voila! It worked!




回答2:


To Publish FEED you have to use "USERID/feed"

Eg: [facebook requestWithGraphPath:@"1231241/feed"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];

and regarding the Properties, i dont think their is any properties with name "properties" is available for feed APIs.

Check out here: http://developers.facebook.com/docs/reference/api/photo/



来源:https://stackoverflow.com/questions/5568642/posting-attachments-with-facebook-graph-api-using-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!