如何发布图片至Facebook墙图形API [英] How to post image to facebook wall with graph api

查看:172
本文介绍了如何发布图片至Facebook墙图形API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要TP张贴在Facebook上wall.I一些文字与图片有从这是否图形API此code,但我想从后捆绑我的形象,而不是从一个链接作为这个API does.Can谁能告诉我如何上传自己的形象而不是链接[变量的setObject:@http://bit.ly/bFTnqdforKey:@链接];在Facebook上墙。

 的NSMutableDictionary *变量= [的NSMutableDictionary dictionaryWithCapacity:4];[变量的setObject:@这是一个测试消息:postMeFeedButton pressedforKey:@消息];* UIImage的画面= [UIImage的imageNamed:@森林fog.jpg];[变量的setObject:@http://bit.ly/bFTnqdforKey:@链接];
[变量的setObject:@这是旁边的图像粗体副本forKey:@名];
[变量的setObject:@这是旁边的图像纯文本副本只工作,不玩耍,聪明的孩子会变傻。 forKey:@说明];FbGraphResponse * fb_graph_response = [fbGraph doGraphPost:@我/饲料withPostVars:变量];
的NSLog(@postMeFeedButton pressed:%@,fb_graph_response.htmlResponse);//我们解析JSON
SBJSON *解析器= [[SBJSON的alloc]初始化];
*的NSDictionary = facebook_response [解析objectWithString:fb_graph_response.htmlResponse错误:无];
[解析​​器释放];//让我们保存的ID的Facebook给了我们,所以如果用户presses了删除/我/饲料按钮,我们可以将其删除
self.feedPostId =(的NSString *)[facebook_response objectForKey:@ID];
的NSLog(@feedPostId,%@,feedPostId);
的NSLog(@现在登录到Facebook和看您的个人资料......);


解决方案

您隐藏图像到数据,并补充说,作为Dictionary.I另一个参数(关键的数据的数据值)在这里给定的样本

  [变量的setObject:为imageData forKey:@数据];

其他的更改

 的UIImage *图片= [UIImage的imageNamed:@森林fog.jpg];NSData的*为imageData = UIImageJPEGRe presentation(图10);
*的NSMutableDictionary PARAMS = [的NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @你的标题消息,@消息,
                               为imageData,@数据
                               零];FbGraphResponse * fb_graph_response = [fbGraph doGraphPost:@我/照片withPostVars:变量];
的NSLog(@postMeFeedButton pressed:%@,fb_graph_response.htmlResponse);

I want tp post some text with image on facebook wall.I have this code from graph api which does that but i want to post my image from bundle and not from a link as this api does.Can anyone tell me how to post your own image rather then the link "[variables setObject:@"http://bit.ly/bFTnqd" forKey:@"link"];" on facebook wall.

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];

[variables setObject:@"this is a test message: postMeFeedButtonPressed" forKey:@"message"];

UIImage *picture = [UIImage imageNamed:@"forest fog.jpg"];

[variables setObject:@"http://bit.ly/bFTnqd" forKey:@"link"];
[variables setObject:@"This is the bolded copy next to the image" forKey:@"name"];
[variables setObject:@"This is the plain text copy next to the image.  All work and no play makes Jack a dull boy." forKey:@"description"];



FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/feed" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);

//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];   
[parser release];

//let's save the 'id' Facebook gives us so we can delete it if the user presses the 'delete /me/feed button'
self.feedPostId = (NSString *)[facebook_response objectForKey:@"id"];
NSLog(@"feedPostId, %@", feedPostId);
NSLog(@"Now log into Facebook and look at your profile...");

解决方案

You covert Image into data and add that as another parameter (Data value for key "data") in the Dictionary.I have given sample here

[variables setObject:imageData forKey:@"data"];

Other Change

UIImage *picture = [UIImage imageNamed:@"forest fog.jpg"];

NSData *imageData = UIImageJPEGRepresentation(picture, 10);


NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"your caption message",@"message", 
                               imageData,@"data",
                               nil];

FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/photos" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);

这篇关于如何发布图片至Facebook墙图形API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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