I'm trying to use facebook within my App by posting a screenshot of my App on my wall.
I already made the functions for taking a screenshot
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
开发者_运维问答
and for posting stuff on my facebook wall with an icon, title and small description.
- (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//\"}]";
}
Any suggestions of how to put my screenshot within the postToWall method? Thanks in advance!
Using Facebook's SDK for iPhone, it is possible. You will need to construct and argument block (NSDictionary) and send that to the your validated Facebook session.
In the snippet here, "session" is of type Facebook * defined in Facebook.h of the SDK.
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];
It seems like you can't do this completely via Facebook. You should look at photo sharing sites for this. First upload your image to that site and get the link. Then share it via this method.
Edit
I am not saying the photo upload isn't possible. It just isn't possible to post a photo to the wall along with a link to your app without uploading it first.
精彩评论