2012-12-10 21 views
2

我總是得到「(#324)需要上傳文件」當我張貼圖片到Facebook,有很多人問這個問題同樣的錯誤,他們大多是使用PHP SDK,看來他們解決了這個問題,通過設置文件上傳至真($ facebook-> setFileUploadSupport(真);),例如:http://endorkins.com/2010/12/28/facebook-graph-api-upload-photos-requires-upload-file/Exception when uploading photo with Facebook Graph API總是得到「(#324)需要上傳文件」,當發佈圖像到Facebook與圖表API

但是我使用圖形API直接在iOS中,我無法找到設置此標誌的位置,我試圖在創建相冊時以及上傳圖像時設置它,但它不起作用。

Facebook圖形API參考(http://developers.facebook.com/docs/reference/api/album/)表示can_upload必須爲true才允許將照片上傳到相冊,我檢查了我試圖上傳圖片的相冊,這是真的。

我也有user_photos,friends_photos,publish_stream,publish_actions的權限。

下面是我發佈圖片的代碼,我花了很多時間在這個上,但無法修復它,請幫助我!任何幫助表示讚賞。

NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/"]; 

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:url]; 

NSMutableDictionary *params = [NSMutableDictionary dictionary]; 

[params setObject:token forKey:@"access_token"]; 

[params setObject:@"the message" forKey:@"message"]; 

NSData *imgData = UIImageJPEGRepresentation(self.img, 1.0); 

[params setObject:imgData forKey:@"source"]; 

NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:[NSString stringWithFormat:@"%@/photos", albumId] parameters:params]; 

[request setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"]; 

//  [request setValue:[NSString stringWithFormat:@"%d", imgData.length] forHTTPHeaderField:@"Content-Length"]; 

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request]; 

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 

} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

     NSLog(@"%@", error); 

     NSLog(@"%@", operation.responseString); 

}]; 

[operation start]; 

回答

1

好了,終於我解決了這個問題,使用facebook SDK發佈圖片。

+0

請你指導我如何在c#web應用程序中做到這一點? –

+0

好吧,但這將是答案http://stackoverflow.com/questions/13236778/facebook-in-ios6-0-use-slrequest-to-upload-a-photo-failed-anyway#13372363 – jose920405

相關問題