2013-01-07 93 views
2

我正在使用最新的Facebook框架創建iOS應用程序3.1
我已經看過很多關於將圖像和文本發佈到Facebook用戶牆上的內容。我使用下面的代碼。iOS - 將圖像和文字發佈到FB用戶的牆上

NSDictionary* dict = @{ 
     @"link" : @"https://developers.facebook.com/ios", 
     @"picture" : [UIImage imageNamed:@"Default"], 
     @"message":@"Your temp message here", 
     @"name" : @"MyApp", 
     @"caption" : @"TestPost", 
     @"description" : @"Integrating Facebook in ios" 
    }; 
[FBRequestConnection startWithGraphPath:@"me/feed" parameters:dict HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
    NSString *alertText; 
    if (error) 
    { 
     NSLog(@"%@",[NSString stringWithFormat: @"error: domain = %@, code = %d", error.domain, error.code]); 
     alertText = @"Failed to post to Facebook, try again"; 
    } else 
    { 
     alertText = @"Posted successfully to Facebook"; 
    } 

    [[[UIAlertView alloc] initWithTitle:@"Facebook Result" message:alertText delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil] show]; 
}]; 

如果我提供的圖片作爲「URL」其發佈的罰款。否則它的投擲錯誤。我想發佈應用程序包內的圖像。有人可以告訴我我的編碼錯在哪裏嗎?

+0

可能重複http://facebook.stackoverflow.com/questions/6702135/post-photo-on-users-wall-using-facebook-ios -sdk) – Igy

+0

看看這個教程 - 它的Facebook SDK 3.0,但會準確地找到你正在尋找的東西 - http://xcodenoobies.blogspot.com/2012/09/how-to-upload-photo-and-update -status.html –

+0

@Igy:使用您建議的網址,我只能張貼照片。我想發佈照片,消息,名稱和URL。 – Satyam

回答

-1
UIImage* image = [UIImage imageNamed:@"nature.jpg"]; 

NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; 
[params setObject:@"My First message" forKey:@"message"];  
[params setObject:image forKey:@"picture"]; 

[FBRequestConnection startWithGraphPath:@"me/photos" parameters:dict HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
    NSString *alertText; 
    if (error) 
    { 
NSLog(@"%@",[NSString stringWithFormat: @"error: domain = %@, code = %d", error.domain, error.code]); 
    alertText = @"Failed to post to Facebook, try again"; 
} else 
{ 
    alertText = @"Posted successfully to Facebook"; 
} 

[[[UIAlertView alloc] initWithTitle:@"Facebook Result" message:alertText delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil] show]; 
}]; 
的[郵政照片上用Facebook的iOS SDK用戶的壁(
+0

這是使用文本和鏈接上傳圖片的最佳方式。 它在Android和iOS上都有工作。 –

相關問題