在我的iphone应用程序中,我想将照片发布到选定的Facebook联系人。我从电话库那里得到那些照片。
我正在使用此代码:
fbString=[NSString stringWithFormat:@"%@\n%@",appdelegate.titleString,appdelegate.descriptionString];
NSArray *permissions =[NSArray arrayWithObjects:@"publish_actions",@"publish_stream",@"manage_friendlists", nil];
NSData* imageData = UIImageJPEGRepresentation(self.img, 90);
NSLog(@"imageData %@",imageData);
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fbString, @"message",imageData,@"source",nil];
NSLog(@"fbid count %d",fbidarray.count);
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error)
{
if (!error) {
for(int j=0;j<fbidarray.count;j++)
{
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos",[fbidarray objectAtIndex:j]] parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error1)
{
NSLog(@"errors in the view %@",error1);
if(!error1 )
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Success"
message:[NSString stringWithFormat:@" Sucessfully posted "]
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}];
}
}
}];
答案 0 :(得分:1)
你可以试试这个:
NSMutableDictionary *postTest = [[NSMutableDictionary alloc]init];
[postTest setObject:[NSString stringWithFormat@"Your message"] forKey:@"message"];
[postTest setObject:@"" forKey:@"picture"];
[postTest setObject:@"" forKey:@"name"];
[postTest setObject:@"APPID" forKey:@"app_id"];
NSString *userFBID =[NSString stringWithFormat:@"%@",[allInfoDict objectForKey:@"Friends facebook ID "]];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/feed?access_token=%@",userFBID,[appDelegate.mysession accessToken]]
parameters:postTest
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
NSDictionary * result,
NSError *error) {
if (error) {
[self hideHUD];
NSLog(@"Error: %@", [error localizedDescription]);
} else {
// Success
}
}];
[postTest release];