I would like to get my iPhone application to post a screenshot to Facebook, but it's not terribly clear from the Facebook Extension example how I would go about doing that.
After logging in, I do the following:
// mySession is the s3eFBSession that was returned after logging in.
s3eFBRequest req = s3eFBRequest_WithGraphPath(mySession, "me/photos", "POST");
// buff is a byte array containing png-formatting image data.
s3eFBRequest_AddParamString(req, "picture", buff);
s3eFBRequest_AddParamString(req, "message", "Check out my new game!");
The output I see in the console is:
FACEBOOK_VERBOSE: calling s3eFacebook func on main thread: s3eFBRequest_WithGraphPath
FACEBOOK_VERBOSE: New request (WithGraphPath): 0x... (0x...)
FACEBOOK_VERBOSE: Add Param String
FACEBOOK_VERBOSE: Add Param String
FACEBOOK_VERBOSE: calling s3eFacebook func on main thread: s3eFBRequest_Send
FACEBOOK_VERBOSE: Sending request
FACEBOOK_VERBOSE: requestWithGraphPath andParams andHttpMethod
FACEBOOK_VERBOSE: requestLoading(with url https://graph.facebook.com/me/photos)
FACEBOOK_VERBOSE: Request sent
FACEBOOK_VERBOSE: didReceiveResponse
FACEBOOK_VERBOSE: didLoadRawResponse
FACEBOOK_VERBOSE: Raw response {"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}
Interestingly enough, if I remove the "message" parameter, I get the following console output:
FACEBOOK_VERBOSE: calling s3eFacebook func on main thread: s3eFBRequest_WithGraphPath
FACEBOOK_VERBOSE: New request (WithGraphPath): 0x... (0x...)
FACEBOOK_VERBOSE: Add Param String
FACEBOOK_VERBOSE: calling s3eFacebook func on main thread: s3eFBRequest_Send
FACEBOOK_VERBOSE: Sending request
FACEBOOK_VERBOSE: requestWithGraphPath
FACEBOOK_VERBOSE: requestLoading(with url https://graph.facebook.com/me/photos)
FACEBOOK_VERBOSE: Request sent
FACEBOOK_VERBOSE: didReceiveResponse
FACEBOOK_VERBOSE: didLoadRawResponse
FACEBOOK_VERBOSE: Raw response {"data":[]}
Which leads me to believe that "picture" is not being properly added as a parameter (despite there being no error message thrown to that effect).
Am I missing something? Obviously adding the image data as a string doesn't seem to be the proper way of doing things, but that's all the Facebook extension seems to offer.












I've verified on an Android device running Java that not including the image data in the request will result in the "324" error that I was seeing above.
Unless someone has a better idea, I'm going to look into adding a s3eFBRequest_AddParamByteArray() method the s3eFacebook extension.
I tried adding methods to s3eFacebook and finished re-writting extension from scratch.
I have not uploaded photos but I think you should get access_token from extension and construct POST request manually
I believe it would be simpler then adding that feature to extension.
Once I got my environment set up, it wound up being trivial. Working in iOS, I added the following method to s3eFacebook_platform.mm:
s3eResult s3eFBRequest_AddParamByteArray_platform(s3eFBRequest* request, const char* name, const unsigned char* value, int length)
{
if (request && name && value)
{
IwTrace(FACEBOOK_VERBOSE, ("Add Param Byte Array"));
NSString *_key = ToNSString(name);
NSData *_value = [NSData dataWithBytes:value length:length];
[request->m_delegate addParamWithValue:_value forKey:_key];
return S3E_RESULT_SUCCESS;
}
return S3E_RESULT_ERROR;
}
The NSData type is properly recognized and handled as a special case in FBRequest.m where is adds the parameters. The image posted properly as a result. I haven't looked into the Android implementation, but it seems like overall this would have been a trivial thing to include in the default code.