-1

在我的 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];

                  }
              }];
         }
 }   
 }];
4

1 回答 1

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];
于 2013-01-22T07:05:26.420 回答