Posting image to facebook Graph API using angularjs
I'm trying to upload an image to facebook ... Unfortunately the facebook API always returns the following error:
{ error: Objectcode: 324, message: "(#324) Requires upload file", type: "OAuthException" }
The image data does not seem to be transmitted correctly. The facebook docs tell me that you are using multipart / form-data upload. (See here > Publishing)
I am using angular-easyfb as a wrapper for my faceebook sdk. What's the easiest way to get this to work? My current code:
var sharePhoto = function() {
ezfb.api("/me/photos",
"POST",
{
"source": content,
"message": "This is a test Photo"
},
function (response) {
console.log("shared", response);
if (response && !response.error) {
/* handle the result */
}
});
};
ezfb.getLoginStatus(function(response) {
if(response.status === 'connected') {
console.log("already conntected", response);
sharePhoto();
} else {
ezfb.login(function(response) {
// Do something with response.
console.log("FB",response);
sharePhoto();
}, {scope: 'public_profile,email,user_photos,publish_actions'});
}
});
Console log:
already conntected {status: "connected", authResponse: Object}
shared {error: {code: 324, message: "(#324) Requires upload file", type: "OAuthException"}}
My questions:
- What is the expected format for my variable content? How do I need to encode?
- Do I need to manipulate the request for request headers? How?
Many thanks for your help!
Edit: Added console log
+3
source to share
No one has answered this question yet
Check out similar questions: