简体   繁体   English

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

[英]How to do wall post on facebook with image stored on iPhone?


I have an application in which i have to post image on Wall of facebook. 我有一个应用程序,我必须在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. 现在的问题是我使用了GraphAPI facebook,我必须传递照片链接,但是我在iPhone中有照片,而不是在任何服务器上。
So how do i post wall with image and other parameters without URL of image? 那么,如何在没有图片网址的情况下发布带有图片和其他参数的墙?

You may use NSURLConnection ASIHttpRequest library for downloading the images from a url. 您可以使用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];
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];

Try using BMSocialShare which is a simple lib I wrote. 尝试使用BMSocialShare ,这是我编写的一个简单库。 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];

Edit: 编辑:

-- -

Actually, posting an image to the Facebook wall has to be from the web. 实际上,将图像发布到Facebook墙上必须来自网络。 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. 也许尝试使用twitpic之类的第三方服务,返回响应网址并将其放在您的参数中。

-- -

You can use the following to post with image to Facebook. 您可以使用以下内容将图像发布到Facebook。 You can also replace UIImage with a physical URL as well. 您也可以将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];

What it will look like: 它会是什么样子:

在此输入图像描述

The house icon is loaded from [UIImage imageNamed:@"something.png"] . 房子图标是从[UIImage imageNamed:@"something.png"]加载的。

I modified the facebook demo app. 我修改了Facebook演示应用程序。 It uses the modal view to select a picture from your phone. 它使用模式视图从手机中选择图片。 You can use this code, granted you must add two buttons (ie, selectPicture button and a uploadPhoto button) -- also be sure to add to UIViewController in the .h file: 您可以使用此代码,前提是您必须添加两个按钮(即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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM