如何在您的应用程序中截取屏幕截图并将其发布到 Facebook 上?

发布于 2024-11-14 05:52:02 字数 1126 浏览 3 评论 0原文

我试图通过在墙上发布我的应用程序的屏幕截图来在我的应用程序中使用 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 方法中,有什么建议吗?提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戏蝶舞 2024-11-21 05:52:02

使用 Facebook 的 iPhone SDK,这是可能的。您需要构建参数块 (NSDictionary) 并将其发送到经过验证的 Facebook 会话。

在此处的代码片段中,“会话”是 SDK 的 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];

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];
萝莉病 2024-11-21 05:52:02

看来你不能完全通过 Facebook 来做到这一点。您应该查看照片共享网站。首先将您的图像上传到该网站并获取链接。然后通过这个方法分享出来。

编辑
我并不是说照片上传是不可能的。如果不先上传照片,就无法将照片连同应用程序的链接发布到墙上。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文