如何通过iPhone应用程序在Facebook上发布照片?
我试图在Facebook上发布图片,但没有成功呢,我 代码:如何通过iPhone应用程序在Facebook上发布照片?
- (void)postToWall{
int im = 1;
NSData *myimgData;
myimgData = [NSData dataWithContentsOfFile:saveImagePath];
//pstimg = myimgData;
NSArray *chunks = [pstimg componentsSeparatedByString: @"."];
NSString *atch= [chunks objectAtIndex: 0];
NSString *filePath = [[NSBundle mainBundle] pathForResource:atch ofType:@"jpg"];
img = [[UIImage alloc] initWithContentsOfFile:filePath];
//start
FBDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
NSString *str = @"Hello";
str = [str stringByReplacingOccurrencesOfString:@" " withString:@"+"];
dialog.cMessage=str;
dialog.userMessagePrompt = @"Enter your message:";
[dialog show];
NSData * findata;
//edited from here
if(im==1)
{
findata = myimgData;
}
else
{
findata = (NSData *)img;
}
NSMutableDictionary * param = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, @"picture",
nil];
FBRequest *uploadPhotoRequest =[FBRequest requestWithDelegate:self] ;
[uploadPhotoRequest call:@"facebook.photos.upload" params:param dataParam:myimgData];
[img release];
}
但它没有公布。
要发布在Facebook上的相片,您需要从Facebook使用iOS SDK:
https://github.com/facebook/facebook-ios-sdk
这里,你会发现与验证示例应用程序和更多,例如张贴的照片。
@Matteo:感谢您的快速回复。我已完成验证部分。和我的文本meassages张贴。我也成功导入图像数据在myimageData.But我认为这段代码不工作:[uploadPhotoRequest调用:@“facebook.photos.upload”params:param dataParam:myimgData]; – 2011-03-28 10:12:06
你从Facebook上得到了一些回拨吗? – 2011-03-28 10:14:30
是的。我的文字已发布,但图像未发布。 – 2011-03-28 10:36:13
在这里看到我的答案http://stackoverflow.com/questions/750328/documented-process-for-using-face-book-connect-for-the-iphone-to-upload-photos/6506549#6506549它使用图形Api上传照片。 – 2011-06-28 13:05:33