2012-05-31 102 views
8
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
           photoDescription, @"message", 
           image, @"image", 
           nil]; 


[facebook requestWithGraphPath:@"me/photos" 
            andParams:params 
           andHttpMethod:@"POST" 
            andDelegate:self]; 

這是我上傳圖片到Facebook所做的。該圖像已成功上傳到FaceBook'照片'。但我想將圖像發佈到我的FaceBook Feed。所以我試了,iPhone在Facebook上發佈圖片

[facebook requestWithGraphPath:@"me/feed" 
            andParams:params 
           andHttpMethod:@"POST" 
            andDelegate:self]; 

但它仍然是發佈到'照片'的圖像。它不會出現在飼料...

我搜索,用不同的方法解決的辦法,但我無法找到任何有用的......

回答

1

不知道你params是什麼樣子,但這種嘗試..

UIImage *image = ...// some image. 

NSData *imageData= UIImagePNGRepresentation(image); 

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
          @"some message", @"message", imageData,@"source", nil]; 

[facebook dialog:@"feed" andParams:params andDelegate:self]; 
+0

我相信這是相同的問題解決方案。換句話說,它只會發佈到用戶時間線,而不是新聞提要。 –

+0

編輯我的答案,利用Facebook的對話方法,而不是圖形請求。現在無法測試,但希望這就是答案 – skram

+0

我剛剛嘗試過您的解決方案,但並未將該圖像發佈到Facebook。我認爲'feed'對話框也是正確的。我也試過'我/飼料'哪個也沒用。 –

0
UIImage* image=...; 
if ([FBSession.activeSession.permissions 
     indexOfObject:@"publish_actions"] == NSNotFound) { 

     NSArray *permissions = 
     [NSArray arrayWithObjects:@"publish_actions",@"publish_stream", nil]; 
     [[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends 
               completionHandler:^(FBSession *session, NSError *error) {}]; 
    } 
    else 
    { 
    NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; 
    [params setObject:@"Photo post test..." forKey:@"message"]; 
    [params setObject:UIImagePNGRepresentation(image) forKey:@"picture"]; 
    //for not allowing multiple hits 

     [FBRequestConnection startWithGraphPath:@"me/photos" 
           parameters:params 
           HTTPMethod:@"POST" 
          completionHandler:^(FBRequestConnection *connection, 
               id result, 
               NSError *error) 
    { 
     if (error) 
     { 
      //showing an alert for failure 
      UIAlertView *alertView = [[UIAlertView alloc] 
             initWithTitle:@"Post Failed" 
             message:error.localizedDescription 
             delegate:nil 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 
      [alertView show]; 

     } 
     else 
     { 
      //showing an alert for success 
      UIAlertView *alertView = [[UIAlertView alloc] 
             initWithTitle:@"Post success" 
             message:@"Shared the photo successfully" 
             delegate:nil 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 
      [alertView show]; 

     } 
    }]; 
    }