任何人都可以帮助我在Facebook上使用目标c发布照片为iphone app.i尝试了但是当我检查iphone.its在simulator中正常工作时它会终止。以下是我用来在fb中发布的代码。我使用graph api来开发我的应用程序。
-(void)fbGraphCallback:(id)sender {
if ((fbGraph.accessToken == nil) || ([fbGraph.accessToken length] == 0)) {
NSLog(@"You pressed the 'cancel' or 'Dont Allow' button, you are NOT logged into Facebook...I require you to be logged in & approve access before you can do anything useful....");
//restart the authentication process.....
[fbGraph authenticateUserWithCallbackObject:self
andSelector:@selector(fbGraphCallback:)
andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins"];
[self.view addSubview:viewshare];
}
else {
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
//imgPicture is my image view name
NSLog(@"the Data::%@\n",imgPicture.image);
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:imgPicture.image];
[variables setObject:graph_file forKey:@"file"];
[variables setObject:[NSString stringWithFormat:@"%@", txtComment.text] forKey:@"message"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/photos" withPostVars:variables];
NSLog(@"postPictureButtonPressed: %@", fb_graph_response.htmlResponse);
NSLog(@"Now log into Facebook and look at your profile & photo albums...");
txtComment.text=@" ";
[txtComment setHidden:YES];
[lblcmt setHidden:YES];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"Successfully posted...Now log into Facebook & look at your profile" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
[fbGraph release];
}
答案 0 :(得分:1)
首先,我检查facebook(facebook对象)是否有有效的会话:
if (![facebook_ isSessionValid]) {
permissions_ = [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", @"offline_access",nil] retain];
[facebook_ authorize:permissions_];
}
当我可以保证我已登录Facebook时,我发布了这样的图像:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image, @"picture",
message, @"message",
nil];
[facebook_ requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
最后,我检查这些方法,以确定图像文章是否成功:
-(void)request:(FBRequest *)request didFailWithError:(NSError *)error {
//Error
}
-(void)request:(FBRequest *)request didLoad:(id)result {
//Succes
}