2011-03-28 160 views
0

我試圖在Facebook上發佈圖片,但沒有成功呢,我 代碼:如何通過iPhone應用程序在Facebook上發佈照片?

- (void)postToWall{ 

int im = 1; 
NSData *myimgData; 
myimgData = [NSData dataWithContentsOfFile:saveImagePath]; 
//pstimg = myimgData; 
NSArray *chunks = [pstimg componentsSeparatedByString: @"."]; 
NSString *atch= [chunks objectAtIndex: 0]; 



NSString *filePath = [[NSBundle mainBundle] pathForResource:atch ofType:@"jpg"]; 


img = [[UIImage alloc] initWithContentsOfFile:filePath]; 

//start 

FBDialog* dialog = [[[FBStreamDialog alloc] init] autorelease]; 

NSString *str = @"Hello"; 
str = [str stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 
dialog.cMessage=str; 

dialog.userMessagePrompt = @"Enter your message:"; 


[dialog show]; 

NSData * findata; 


    //edited from here 


    if(im==1) 
    { 
     findata = myimgData;  

    } 
    else 
    { 
     findata = (NSData *)img; 

    } 

    NSMutableDictionary * param = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            img, @"picture", 
            nil]; 

    FBRequest *uploadPhotoRequest =[FBRequest requestWithDelegate:self] ; 
    [uploadPhotoRequest call:@"facebook.photos.upload" params:param dataParam:myimgData]; 



    [img release]; 

}

但它沒有公佈。

+0

在這裏看到我的答案http://stackoverflow.com/questions/750328/documented-process-for-using-face-book-connect-for-the-iphone-to-upload-photos/6506549#6506549它使用圖形Api上傳照片。 – 2011-06-28 13:05:33

回答

1

要發佈在Facebook上的相片,您需要從Facebook使用iOS SDK:

https://github.com/facebook/facebook-ios-sdk

這裏,你會發現與驗證示例應用程序和更多,例如張貼的照片。

+0

@Matteo:感謝您的快速回復。我已完成驗證部分。和我的文本meassages張貼。我也成功導入圖像數據在myimageData.But我認爲這段代碼不工作:[uploadPhotoRequest調用:@「facebook.photos.upload」params:param dataParam:myimgData]; – 2011-03-28 10:12:06

+0

你從Facebook上得到了一些回撥嗎? – 2011-03-28 10:14:30

+0

是的。我的文字已發佈,但圖像未發佈。 – 2011-03-28 10:36:13

相關問題