2012-07-19 139 views
0

我正嘗試在iPad應用程序的Facebook牆上發佈圖片。但是沒有任何事情發生,Facebook網站彈出來允許它,但圖像從未發佈。這是我的代碼:在Facebook牆上發佈圖片

-(IBAction)facebookButton { 
    facebook = [[Facebook alloc] initWithAppId: APP_ID andDelegate:self]; 

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { 
     facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; 
     facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; 
    } 

    if (![facebook isSessionValid]) { 
     [facebook authorize:nil]; 
    } 

    [facebook authorize:[NSArray arrayWithObjects: @"publish_stream",@"user_photos", nil]]; 

    UIImage* image = [UIImage imageNamed: @"image.png"]; 
    NSData* imgData = UIImagePNGRepresentation(image); 
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
                  @"Hey", @"message", //whatever message goes here 
                  imgData, @"data", //img is your UIImage 
                  nil]; 
    [facebook requestWithGraphPath:@"me/photos" 
             andParams:params 
           andHttpMethod:@"POST" 
            andDelegate:self]; 
} 

回答

1

您已經將後置零件置於fbDidLogin方法中。

此外,這與您的問題完全不相關,但是我注意到您發佈的代碼,您不必將圖像轉換爲NSData,如果您希望將UIImage本身置於鍵下picture,它會被上傳。

+0

謝謝!這與[this](http://stackoverflow.com/questions/5783782/fbdidlogin-not-called-ios#answer-6138046)結合起來了! – Labbekak 2012-07-20 13:14:10