あなたは、Facebookの最新のiOS SDKを使用している場合は、Hackbookサンプルアプリでは、APICallsViewController.mファイルを探します。この方法はUIImageを使って直接投稿することができます:
/*
* Graph API: Upload a photo. By default, when using me/photos the photo is uploaded
* to the application album which is automatically created if it does not exist.
*/
- (void) apiGraphUserPhotosPost {
NSString *sourcePath = [[NSBundle mainBundle] resourcePath];
NSString *file1 = [sourcePath stringByAppendingPathComponent:@"/MP1101frame1002.jpg"];
UIImage *img = [[[UIImage alloc]initWithContentsOfFile:file1]autorelease];
[self showActivityIndicator];
currentAPICall = kAPIGraphUserPhotosPost;
HackbookAppDelegate *delegate = (HackbookAppDelegate *) [[UIApplication sharedApplication] delegate];
// Download a sample photo
NSURL *url = [NSURL URLWithString:@"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
// UIImage *img = [[UIImage alloc] initWithData:data]; //here you can insert your UIImage
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
yourMessageHere, @"message", //whatever message goes here
img, @"picture", //img is your UIImage
nil];
[[delegate facebook] requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
}
はい、私は画像をアップロードする方法を知っています。しかし、画像とともにコメントを投稿するには? –
私はちょうどメッセージを含める方法を示す私の答えを編集しました。それは:yourMessageHere、@ "message"です。 yourMessageHereはNSStringです。 "message"はparams辞書のキーです。 – user523234
"ユーザーにコメントの入力が求められないため、機能しません" - コメントを書くようにしたい場合はどうすればいいですか?私はCocoaでプロンプトを自分自身で実装する必要がありますか、Facebook APIを手助けする方法はありますか? –