如何发布照片。 iOS Facebook SDK 3.1

编程入门 行业动态 更新时间:2024-10-27 18:31:34
本文介绍了如何发布照片。 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

本文发布于:2023-10-11 04:34:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1480699.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:照片   iOS   Facebook   SDK

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!