我有一个应用程序,我必须在Facebook的墙上发布图像
现在的问题是我使用了GraphAPI facebook,我必须通过照片的链接,但我的iPhone上有照片,而不是任何服务器。
那么如何在没有图像URL的情况下使用图像和其他参数发布墙?
答案 0 :(得分:2)
您可以使用NSURLConnection ASIHttpRequest库从网址下载图片。
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];
答案 1 :(得分:1)
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];
答案 2 :(得分:0)
-
实际上,将图片发布到Facebook墙上必须来自网络。所以你必须先上传图片;也许尝试第二方服务,如twitpic或其他东西,返回响应网址并将其放在你的参数中。
-
您可以使用以下内容将图片发布到Facebook。您也可以将UIImage
替换为物理网址。
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"]
加载。
答案 3 :(得分:0)
我修改了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];
}
答案 4 :(得分:0)
尝试使用BMSocialShare这是我写的一个简单的lib。它正是你想要的。上传一些本地图像(甚至打开用户添加注释的对话框)到用户的墙上:
BMFacebookPost *post = [[BMFacebookPost alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
[[BMSocialShare sharedInstance] facebookPublish:post];