2010-06-02 104 views
1

我正在將facebook與我的iphone應用程序集成。我可以在Facebook上分享 短信,但我想通過我的iPhone應用程序分享/上傳 照片到Facebook。 請讓我知道是否有這種飲料。 我正在嘗試Facebook的示例代碼,但它給了我一些 錯誤:我找出了那個錯誤,但其他開發人員也面臨這種類型的錯誤 。請讓我知道是否有 某人在facebook上申請上傳/分享照片。如何通過iPhone應用程序將照片/圖像加載到Facebook

在此先感謝。

+0

可能[使用Facebook連接的iPhone上傳照片的文檔化過程]的副本(http://stackoverflow.com/questions/750328/documented-process-for-using-facebook-connect-for-the-iphone-to-upload -相片) – 2010-06-03 02:52:54

回答

1

你需要上傳圖像創建相冊,U創造了通過,你必須使用其ID上傳照片

// for making a facebook album u have to make a multi-part form request 
//to this url https://graph.facebook.com/100002232753228/albums 
//where 100002232753228 is the fbid of the user and with form fields access_token,name,message, for reference go to -http://developers.facebook.com/docs/reference/api/album/ 

//To upload a foto to album send multi-part data to the url - https://graph.facebook.com/102657189818706/photos 

//where 102657189818706 is the facebook id of the album created 

這裏的Facebook API專輯後的代碼

#define kRequestBoundary @"----FOO" 

    NSMutableData *postBody = [[NSMutableData alloc] init]; 
    [postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", kRequestBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; //starting the boundary of form data 

         [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"access_token\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; //setting field name of access_toke 
         [postBody appendData:[[NSString stringWithString:@"200726069952695|fd9c7d8ed4b5592b1240cdb3-100002232753228|i7ae5By6VFItLliVT1jw5jsETEY"] dataUsingEncoding:NSUTF8StringEncoding]]; 
    //setting field value of access_token 

    [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", kRequestBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; //closing the boundary for next field 

    [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"image\"; filename=\"UserImage.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
//setting the field name of image 

    [postBody appendData:[[NSString stringWithString:@"Content-Type: image/png\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; //setting the content-Type of image 



     UIImage *cropped=[UIImage imageNamed:@"Sample.png"]; 



    NSData *pImageData = UIImagePNGRepresentation(cropped); 


    [postBody appendData:pImageData]; // adding image data to the request data 

    [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",kRequestBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; //closing the 


    NSString *urlString = @"https://graph.facebook.com/102657189818706/photos"; 


    NSMutableURLRequest *request=[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:pUrl]]; 
    self.mURLrequest=request; 
    [request release]; 
    [pUrl release]; 
    [request setHTTPMethod:@"POST"]; 

    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", kRequestBoundary]; 

    [request setValue:contentType forHTTPHeaderField:@"Content-type"]; 
    [mURLrequest setHTTPBody:postBody]; 


    NSURLConnection *temp=[[NSURLConnection alloc] initWithRequest:mURLrequest delegate:self]; 
[temp autorelease]; 
相關問題