如何通过iphone以编程方式在Facebook墙上发布大图像。我正在使用FBConnect API如何实现这一目标。
由于
答案 0 :(得分:0)
Facebook docs说:
强烈建议您在将应用程序中的图像添加到请求之前对其进行缩放。最大尺寸应至多为720像素(Facebook支持的最大显示尺寸)。
答案 1 :(得分:0)
-(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];
}
答案 2 :(得分:0)
使用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];
}