2010-03-23 64 views
0

這裏Iam有一個問題。其實我在我的應用程序中實現了Facebook集成,我需要發佈圖像的文字,但我沒有任何想法如何在這個工作。任何人都可以用示例代碼來提示,這對我非常有幫助。如何發佈圖像與文本在facebook集成在iphone sdk

任何人的幫助將不勝感激。

+0

傢伙請給我一個及時的解決方案。 – monish 2010-03-23 08:49:25

+0

你的意思是你想上傳包含文字的圖片,或發佈帶有標題,標題和圖片的Facebook流? – zonble 2010-03-24 21:19:25

+0

我想發佈帶有標題標題和圖片的圖片,但我想發佈存儲在我的數據庫中的圖片,而不是一個鏈接,你可以再建議嗎? – monish 2010-03-25 04:45:59

回答

2

我假設你想在圖像中繪製一些文字,然後將圖像上傳到Facebook。

首先,我們需要將原始圖像和所需文本繪製到新圖像中。

UIGraphicsBeginImageContext(CGSizeMake(320.0, 320.0)); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
// Draw the original image 
[image drawInRect:CGRectMake(0, 0, 320.0, 320.0)]; 
// Draw the text 
[@"text" drawInRect:CGRectMake(...) withFont:[UIFont systemFontOfSize:20.0]; 

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

然後,將圖像轉換成NSData並調用Facebook的「photos.upload」API來上傳它。

NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease]; 
[args setObject:@"caption" forKey:@"caption"];  
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self]; 
NSData *data = UIImagePNGRepresentation(newImage); 
[uploadPhotoRequest call:@"photos.upload" params:args dataParam:data]; 
1

如果你想上傳圖片到你的服務器,併發佈一個小故事到Facebook的牆上。使用流API。

FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease]; 
dialog.delegate = self; 
dialog.userMessagePrompt = @"Prompt"; 

NSString *name = @"Your caption"; 
NSString *src = @"http://example.com/path/of/your/image"; 
NSString *href = @"http://what/happens/if/the/user/click/on/the/image"; 

NSString *attachment = [NSString stringWithFormat:@"{\"name\":\"%@\",\"media\":[{\"type\":\"image\", \"src\":\"%@\", \"href\":\"%@\"}]}", name, src, href]; 
dialog.attachment = attachment; 
[dialog show]; 
0

也許你會很樂意使用BMSocialShare。這是我寫的一個簡單的lib。

BMFacebookPost *post = [[BMFacebookPost alloc] 
         initWithTitle:@"Simple sharing via Facebook, Email and Twitter for iOS!" 
         descriptionText:@"Posting to Facebook, Twitter and Email made dead simple on iOS. Simply include BMSocialShare as a framework and you are ready to go." 
         andHref:@"https://github.com/blockhaus/BMSocialShare"];  

[post setImageUrl:@"http://www.blockhausmedien.at/images/logo-new.gif" 
     withHref:@"http://www.blockhaus-media.com"]; 

[[BMSocialShare sharedInstance] facebookPublish:post]; 
相關問題