2012-10-20 91 views

回答

24

這是我發現

- (void) postImageToFB:(UIImage*)image 
{ 
    NSData* imageData = UIImageJPEGRepresentation(image, 90);  
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            @"This is my drawing!", @"message", 
            imageData, @"source", 
            nil]; 

    [FBRequestConnection startWithGraphPath:@"me/photos" 
           parameters:params 
           HTTPMethod:@"POST" 
          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 

          }]; 
} 

,如果你想發佈一個朋友的牆,由@"[friendID]/photos"

改變@"me/photos"然後,要求授權發佈和調用的方法最簡單的方法

if ([FBSession.activeSession.permissions indexOfObject:@"publish_stream"] == NSNotFound) 
{ 
    // No permissions found in session, ask for it 
    [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_stream"] 
               defaultAudience:FBSessionDefaultAudienceFriends 
              completionHandler:^(FBSession *session, NSError *error) 
    { 
     // If permissions granted, publish the story 
     if (!error) [self postImageToFB:currentDrawing]; 
    }]; 
} 
// If permissions present, publish the story 
else [self postImageToFB:currentDrawing]; 

的「[應用程序名稱]的照片」相冊將被創建,如果它不存在

它適合我!

+4

沒有必要的NSData的,只是把它保存爲一個UIImage的,改變圖像鍵爲「圖片報」圖API將處理其餘部分:-) –

+0

您在UIImageJPEGRepresentation上的壓縮應該在0-1.0之間..所以,而不是90,你的意思是.9 – badweasel

相關問題