Reputation: 5118
I've seen a couple posts about this issue, but so far nothing has seemed to help me. Basically, I'm writing an iOS app and attempting to post a photo to a Facebook album using the Graph API. The image data is first downloaded from a server, and then POSTed to Facebook. I'm using the ASIFormDataRequest class and the url https://graph.facebook.com/MY_ALBUM_ID/photos, but I'm consistently getting the following error:
error = {
message = "(#1) An unknown error occurred";
type = OAuthException;
};
My request looks like this:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:url]];
self.photoRequest = request;
[request setDelegate:self];
[request setPostValue:token forKey:@"access_token"];
[request setPostValue:message forKey:@"message"];
[request setTimeOutSeconds:240];
[request setRequestMethod:@"POST"];
UIImage *image = [UIImage imageWithData:data];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *imageData = UIImageJPEGRepresentation(image, 0.8);
[request setData:imageData forKey:@"source"];
dispatch_async(dispatch_get_main_queue(), ^{
[request startAsynchronous];
});
});
The strange part is that I'm using the exact same method to upload photos to my server for a different part of the application, and everything works fine. I've even uploaded the photo I'm trying to send to Facebook to my server to see if the data was POSTing correctly. Everything came out okay.
I've read that Facebook can sometimes spit back the error I'm seeing if it has a problem with the image format, but the error in and of itself is pretty nebulous. I know my access_token is valid. All other requests I'm making to Facebook are working just fine.
Any thoughts?
Upvotes: 5
Views: 5686
Reputation: 2092
Like stated in this answer the problem can be caused when your application is in Sandbox mode.
Upvotes: 0
Reputation: 514
There is an image restriction that is not documented, or at least I couldn't found anything, the aspect ratio limit is 1:3 when the height is bigger than the width on the image. I did many tests to confirm this and I can assure you this is the limit as of today.
Upvotes: 0
Reputation: 5118
Okay so, I figured it out!
As it happens, Facebook has ratio restrictions to uploaded images. I'm still not sure what they are, but in my case, a 198x715 image didn't fit their ratio requirements. We contacted one of the guys we know on the Facebook dev team, and he said that they weren't going to change the restrictions, but they would add better messaging to the API error.
Hope that helps anybody out there with similar problems.
Upvotes: 3