如何使用 iPhone 上存储的图像在 Facebook 上发布墙帖?

发布于 2024-11-06 20:22:21 字数 150 浏览 0 评论 0原文


我有一个应用程序,我必须在 facebook 墙上发布图像。
现在的问题是我使用 GraphAPI facebook,我必须传递照片链接,但我的 iPhone 中有照片,而不是在任何服务器上。
那么如何在没有图像 URL 的情况下发布包含图像和其他参数的墙呢?

I have an application in which i have to post image on Wall of facebook.
Now problem is i used GraphAPI facebook and i have to pass link of photo but i have photo in my iPhone and not on any server.
So how do i post wall with image and other parameters without URL of image?

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

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

发布评论

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

评论(5

风追烟花雨 2024-11-13 20:22:21

您可以使用 NSURLConnection ASIHttpRequest 库从 url 下载图像。

You will have to do the following:
1. Create a NSUrlConnection and implement the delegate methods
2. Pass the url in your request and you will get the data in -(void)connectionDidFinishLoading: (NSURLConnection *)connection
3. You can then create a UIImage from this data using UIImage *image = [[UIImage alloc] initWithData:activeDownloadData];

You may use NSURLConnection ASIHttpRequest library for downloading the images from a url.

You will have to do the following:
1. Create a NSUrlConnection and implement the delegate methods
2. Pass the url in your request and you will get the data in -(void)connectionDidFinishLoading: (NSURLConnection *)connection
3. You can then create a UIImage from this data using UIImage *image = [[UIImage alloc] initWithData:activeDownloadData];
烈酒灼喉 2024-11-13 20:22:21
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = @"Enter your message:";

NSDictionary *params = nil;
[[FBRequest requestWithDelegate:self] call:@"facebook.photos.upload" params:params dataParam:(NSData*)wallImage];
[dialog show];
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = @"Enter your message:";

NSDictionary *params = nil;
[[FBRequest requestWithDelegate:self] call:@"facebook.photos.upload" params:params dataParam:(NSData*)wallImage];
[dialog show];
江南烟雨〆相思醉 2024-11-13 20:22:21

编辑:

--

实际上,将图像发布到 Facebook 墙必须来自网络。所以你必须先上传图片;也许尝试使用 twitpic 之类的第 3 方服务,返回响应 URL 并将其放入您的参数中。

--

您可以使用以下命令将图像发布到 Facebook。您还可以将 UIImage 替换为物理 URL。

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               kAppID, @"app_id",
                               @"http://bit.ly/dDZQXt", @"link",
                               @"www.has.to.be.web.based.com", @"picture",
                               EasyStrings(@"Mobile Profiles for ",device), @"name",
                               EasyStrings(@"Current Profile: ",currProfile), @"caption",
                               @"I am using Mobile Profiles for iPhone, iPod touch and iPad.", @"description",
                               message,  @"message",
                               nil];
[_facebook dialog:@"feed"
        andParams:params
      andDelegate:self];

它会是什么样子:

在此处输入图像描述

房子图标是从 [UIImage imageNamed:@"something .png"]

Edit:

--

Actually, posting an image to the Facebook wall has to be from the web. So you will have to upload the image first; maybe try a 3rd party service like twitpic or something, return the response url and place it in your params.

--

You can use the following to post with image to Facebook. You can also replace UIImage with a physical URL as well.

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               kAppID, @"app_id",
                               @"http://bit.ly/dDZQXt", @"link",
                               @"www.has.to.be.web.based.com", @"picture",
                               EasyStrings(@"Mobile Profiles for ",device), @"name",
                               EasyStrings(@"Current Profile: ",currProfile), @"caption",
                               @"I am using Mobile Profiles for iPhone, iPod touch and iPad.", @"description",
                               message,  @"message",
                               nil];
[_facebook dialog:@"feed"
        andParams:params
      andDelegate:self];

What it will look like:

enter image description here

The house icon is loaded from [UIImage imageNamed:@"something.png"].

冷…雨湿花 2024-11-13 20:22:21

我修改了 Facebook 演示应用程序。它使用模态视图从手机中选择图片。您可以使用此代码,前提是您必须添加两个按钮(即 selectPicture 按钮和 uploadPhoto 按钮)——还要确保添加到 .h 文件中的 UIViewController:

/**
 * Upload a photo.
 */
- (IBAction)uploadPhoto:(id)sender {

  NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 image, @"picture",
                                 nil];

  [_facebook requestWithGraphPath:@"me/photos"
                        andParams:params
                        andHttpMethod:@"POST"
                        andDelegate:self];

}

/**
 * Select a photo.
 */
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [self dismissModalViewControllerAnimated:YES];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction) selectPicture:(UIButton *)sender;
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

I modified the facebook demo app. It uses the modal view to select a picture from your phone. You can use this code, granted you must add two buttons (i.e., selectPicture button and a uploadPhoto button) -- also be sure to add to UIViewController in the .h file:

/**
 * Upload a photo.
 */
- (IBAction)uploadPhoto:(id)sender {

  NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 image, @"picture",
                                 nil];

  [_facebook requestWithGraphPath:@"me/photos"
                        andParams:params
                        andHttpMethod:@"POST"
                        andDelegate:self];

}

/**
 * Select a photo.
 */
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [self dismissModalViewControllerAnimated:YES];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction) selectPicture:(UIButton *)sender;
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}
国产ˉ祖宗 2024-11-13 20:22:21

尝试使用 BMSocialShare 这是我编写的一个简单的库。它正是在做你想做的事。将一些本地图像(甚至打开一个对话框供用户添加评论)上传到用户墙上:

BMFacebookPost *post = [[BMFacebookPost alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
[[BMSocialShare sharedInstance] facebookPublish:post];

Try using BMSocialShare which is a simple lib I wrote. It is exactly doing what you want. Upload some local image (and even open a dialog for the user to add a comment) to the user's wall:

BMFacebookPost *post = [[BMFacebookPost alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
[[BMSocialShare sharedInstance] facebookPublish:post];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文