繁体   English   中英

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

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


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

您可以使用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];

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

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

编辑:

-

实际上,将图像发布到Facebook墙上必须来自网络。 因此,您必须首先上传图像; 也许尝试使用twitpic之类的第三方服务,返回响应网址并将其放在您的参数中。

-

您可以使用以下内容将图像发布到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"]加载的。

我修改了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];
}

暂无
暂无

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

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