我试图在我的应用程序中使用Facebook,通过在我的墙上发布我的应用程序的屏幕截图.
我已经制作了拍摄截图的功能
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
并在我的Facebook墙上发布图标,标题和小描述的东西.
- (void)postToWall {
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = @"Enter your message:";
dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@ share's a photo\",\"href\":\"mywebsite.com/\",\"caption\":\"%@thinks this is a nice photo\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"mywebsite.com/icon.png\",\"href\":\"mywebsite.com/\"}]}",
_facebookName, _facebookName];
dialog.actionLinks = @"[{\"text\":\"Get My App\",\"href\":\"http://itunes.apple.com//\"}]";
}
有关如何将我的屏幕截图放在postToWall方法中的任何建议?提前致谢!
最佳答案 使用Facebook的iPhone SDK,它是可能的.您将需要构造和参数块(NSDictionary)并将其发送到您验证的Facebook会话.
在这里的代码片段中,“session”是在Facebook的Facebook.h中定义的Facebook *类型.
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:captionText forKey:@"caption"];
[args setObject:messageText forKey:@"message"];
[args setObject:UIImageJPEGRepresentation(yourImage, 0.7) forKey:@"picture"];
[session requestWithMethodName:@"photos.upload" andParams:args ndHttpMethod:@"POST" andDelegate:self];