本文介绍了如何发布照片。 iOS Facebook SDK 3.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的墙上发布一张照片。图片是在我的iPad应用程序中生成的。解决方案
这是我找到的最简单的方法
- (void)postImageToFB:(UIImage *)image { NSData * imageData = UIImageJPEGRepresentation(image,90); NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @这是我的绘图!,@message, imageData,@source, nil]; [FBRequestConnection startWithGraphPath:@me / photos参数:params HTTPMethod:@POST completionHandler:^(FBRequestConnection * connection,id result, NSError * error){ }]; }如果要在朋友的墙上张贴,请更改 @我/照片 by @[friendID] / photos
然后,请求发布权限并调用方法
if([FBSession.activeSession.permissions indexOfObject:@publish_stream ] == NSNotFound) { //在会话中找不到权限,请求 [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@publish_stream] defaultAudience: FBSessionDefaultAudienceFriends completionHandler:^(FBSession * session,NSError * error) { //如果权限授予,发布故事 if(!error)[self postImageToFB:currentDrawing] ; }]; } //如果存在权限,发布故事 else [self postImageToFB:currentDrawing];如果不存在,将创建一个[App Name] Photos相册
它对我有用!
I needed to publish a picture on my wall. The pic is generated in my iPad app.
解决方案This is the simplest way I've found
- (void) postImageToFB:(UIImage*)image { NSData* imageData = UIImageJPEGRepresentation(image, 90); NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"This is my drawing!", @"message", imageData, @"source", nil]; [FBRequestConnection startWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { }]; }if you want to post on a friend's wall, change @"me/photos" by @"[friendID]/photos"
Then, ask for permissions to publish and call the method
if ([FBSession.activeSession.permissions indexOfObject:@"publish_stream"] == NSNotFound) { // No permissions found in session, ask for it [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_stream"] defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error) { // If permissions granted, publish the story if (!error) [self postImageToFB:currentDrawing]; }]; } // If permissions present, publish the story else [self postImageToFB:currentDrawing];An "[App Name] Photos" album will be created, if doesn't exist
It does work for me!
更多推荐
如何发布照片。 iOS Facebook SDK 3.1
发布评论