2013-01-22 46 views
-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]; 

        } 
       }]; 
     } 
} 
}]; 
+0

我懷疑在for循環,它是快速和它不會等待,所以不要做'startWithGraphPath:循環。完成後發送另一個請求。 – TheTiger

+0

'NSData * imageData = UIImageJPEGRepresentation(self.img,90);'也是錯誤的** compressionQuality **是b/w 0到1. – TheTiger

+0

我已經嘗試過這一點,問題是與「key」,BTW你有圖像URL? –

回答

1

你可以試試這個:

NSMutableDictionary *postTest = [[NSMutableDictionary alloc]init]; 
    [postTest setObject:[NSString [email protected]"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];