在脸书上张贴大图
Posted
技术标签:
【中文标题】在脸书上张贴大图【英文标题】:Posting larger image on facebook 【发布时间】:2011-09-27 10:02:28 【问题描述】:如何通过 iphone 以编程方式在 facebook 墙上发布大图像。我正在使用 FBConnect API 我如何实现这一点。
谢谢
【问题讨论】:
即使您发送原始图像,facebook也会自动将其调整为720x720(或其他)。因此 facebook 建议在发送前将图像大小调整为最大 720px,以节省发送时的用户流量/时间。 【参考方案1】:Facebook docs 说:
强烈建议您先在应用程序中缩放图像,然后再将其添加到请求中。最大尺寸应不超过 720 像素(Facebook 支持的最大显示尺寸)。
【讨论】:
【参考方案2】:用 Graph API 试试这个
- (IBAction)uploadPhoto:(id)sender
NSString *path = @"http://www.facebook.com/images/devsite
/iphone_connect_btn.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, @"picture",
nil];
[_facebook requestWithGraphpath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
[img release];
【讨论】:
【参考方案3】:-(void)postMessageWithPictureOnFB
NSString *urlString = [[NSString alloc] initWithFormat:@"https://graph.facebook.com/me/photos"];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSData *picture_data = UIImagePNGRepresentation([UIImage imageNamed:@"apple.png"]);
NSMutableData *body = [[NSMutableData alloc] initWithCapacity:1];
NSString *boundary = [[NSString alloc] initWithString:@"----1010101010"];
NSString *contentType = [[NSString alloc] initWithFormat:@"multipart/form-data; boundary=%@",boundary];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"message\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[textView.text dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"media\";\r\nfilename=\"media.png\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:picture_data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"access_token\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[facebook.accessToken dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
serverRequest = [ASIHTTPRequest requestWithURL:url];
[serverRequest addRequestHeader:@"Content-Type" value:contentType];
[serverRequest appendPostData:body];
[serverRequest addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d", body.length]];
//[serverRequest setDelegate:self];
//[serverRequest setDidFinishSelector:@selector(postMessageWithPictureOnFBRequestDone:)];
//[serverRequest setDidFailSelector:@selector(postMessageWithPictureOnFBRequestWentWrong:)];
[serverRequest startAsynchronous];
[urlString release];
[url release];
[body release];
[boundary release];
[contentType release];
【讨论】:
以上是关于在脸书上张贴大图的主要内容,如果未能解决你的问题,请参考以下文章