how to upload image with feed using FB.api method - facebook

we are using Fb API for post feed on facebook.
my code is -
if (response.authResponse) {
var data =
{
name: "link to apply",
picture: 'http://www.hrgp.biz/Uploads/CompanyForTesting_499/NotesReminders/2608chemtec-logo.jpg',
link: "http://www.hrgp.biz/bc0efdb3-f1a7-4d81-9635-d1418e808b6d.aspx", // Go here if user click the picture
description: "thank you"
}
FB.api('me/feed', 'post', data, function (response) {
if (!response || response.error) {
alert(JSON.stringify(response.error));
} else {
//alert('Post ID: ' + response.id);
alert('feed posted successfully.');
}
});
}
}, { scope: 'email,user_likes,publish_actions,publish_stream,read_stream,photo_upload' });
This code Works but I’m having issues with the picture. It doesn’t show up in the post.
how can i resolve this issue?
or
please tell me if any problem into my code.
thank you..!!!

Please refer to What is the minimum width and height Of Facebook Open Graph Images?.
The ratio of both height divided by width and width divided by height
(w/h, h/w) cannot exceed 3.0.
Your photo, http://www.hrgp.biz/Uploads/CompanyForTesting_499/NotesReminders/2608chemtec-logo.jpg, 250/65 = 3.84615384615 obviously exceed the maximum ratio:

FB.api('me/feed', 'post', { message: body,
picture :'PICTURE_URL',
description : "DESCRIPTION"
}
, function (res) {
if(!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log('Post Id: ' + res.id);
for more options check - https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed

Related

How to use facebook API to post to my own page

I had the ability to post from my website to my page some time ago, it seems there have been some changes made to the API since then now when I use the below snippets I get the error message
{"message":"(#100) Only owners of the URL have the ability to specify the picture, name, thumbnail or description params.","type":"OAuthException","code":100,"fbtrace_id":"AsGjV6ebkihnC60tRtHM4f3"}
Code
function postToFeed(id, desc, name) {
var page_id = ************;
var app_id = ************;
FB.api('/' + page_id, {
fields : 'access_token'
}, function(resp) {
console.log(resp);
if (resp.access_token) {
FB.api('/' + page_id + '/feed', 'post', {
message : desc,
link : 'https://link',
name : name,
from : page_id,
description :'',
access_token : resp.access_token
}, function(response) {
if (!response || response.error) {
alert(JSON.stringify(response.error));
} else {
alert('Post ID: ' + response.id);
}
});
}
});
Yes, like the error message suggests, this changed some time ago. See the respective section
Custom Link Page Post Image
in the docs for more information: https://developers.facebook.com/docs/graph-api/reference/v3.3/page/feed
You can of course also just remove the custom description parameter.

Facebook post 360 image

I am having trouble posting a 360 image on Facebook via the Graph API. I can post an image just fine though. The issue is that the meta data I used for the image seems to be not working for some reasons. When I manually upload the image it is detected as a 360 image but not programatically. Is there something I am missing? A parameter missing in my spherical_metadata or a wrong parameter?
Here is the code I use to post a photo on facebook:
function Facebook_Share(textToPost)
{
var imgURL="http://panorama.2020.net/view/ybcjxd4hugnmeyvaorug/panorama.jpg";
FB.api('me/photos', 'post', {
message: textToPost,
spherical_metadata : { "ProjectionType" : "equirectangular", "CroppedAreaImageWidthPixels" : "1696", "CroppedAreaImageHeightPixels" : "848", "FullPanoWidthPixels" : "4000",
"FullPanoHeightPixels" : "2000", "CroppedAreaLeftPixels" : "566", "CroppedAreaTopPixels" : "283" },
url:imgURL
}, function(response){
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
document.getElementById("myTextarea").value = "";
}
});
}
PS: The site url isn't the one i'm using right now to test my facebook image. I only use it to retrieve the image until my feature is working properly.
Solution by OP.
To make it 360 on facebook, add the parameter "allow_spherical_photo": true in the FB.API call.

Post a public message in Facebook with FB.api

I have tried to post a message on my wall using FB.api(). I posted it successfully but it's showing only for me. I want to make this post public.
In app Configuring permissions i set "Default Activity Privacy" value Public but still message posting private.
I tried to do it by following code:
FB.login(function (response) {
if (response.authResponse) {
var privacy = { 'value': 'EVERYONE' };
var txt = 'my post to test feed post using api';
FB.api('me/feed', 'post', { message: txt, privacy: privacy }, function (response) {
if (!response || response.error) {
alert(JSON.stringify(response.error));
} else {
alert('Post ID: ' + response.id);
}
});
}
}, { scope: 'email,user_likes,publish_actions,publish_stream,read_stream' });
Please check my code.
As said in reference 'privacy' field value should be string.
Try to pass "{ 'value': 'EVERYONE' }" as string, not an object.

How to post Flash applets to a wall on Facebook?

In the comments of this question, users have commented that it's possible to insert a Flash applet into a Facebook wall post. I was under the impression this isn't possible without making a FB app.
I'm aware that FB will convert links to various media types - e.g. a link to a MP3 becomes automagically a SWF MP3 player, but the Flash applet used is chosen by FB's internal logic, not by the content of the post. Is it possible to embed a SWF applet of your own choosing?
As I haven't been able to find any documentation on this, has anyone else? Or, do you have some PoC code that does this?
you can use the Facebook's JS-SDK for it:
FB.ui(
{
method: 'feed',
name: 'Title pf post',
link: 'http://link.to.target',
picture: 'http://link.to.previewimage',
source: 'http://link.to.swf',
caption: 'Subtitle',
description: 'Maintext',
},
function(response) {
if (response && response.post_id) {
//alert('Post was published.');
} else {
//alert('Post was not published.');
}
}
);
As you said in the comment of the other question, that you were also interested in how to pass parameters to the swf, here is the solution:
in javascript
function postOnWall(fbuid) {
var params = {};
params['message'] = "my message";
params['name'] = "my name";
params['description'] = "my description";
params['link'] = "https://www.mylink.com";
params['caption'] = "my caption";
params['picture'] = "https://www.mylink.de/thumb.png";
params['source'] = "https://www.mylink.de/Main.swf" + "?bla=thisisyourdynamicquerystring";
FB.api('/' + fbuid + '/feed', 'post', params, function(response) {
if (!response || response.error) {
// Error occured while publishing to stream
} else {
// Published to stream
}
});
}
in actionscript
public function Main() {
this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
}
private function loaderComplete(event : Event) : void {
var myQueryStrings : Object = this.loaderInfo.parameters;
if (myQueryStrings && myQueryStrings.bla) {
_myMovie.label.text = myQueryStrings.bla;
}
}

Sencha Touch and Facebook button

I need to create a button to submit a comment on Face Book wall.
I am using MVC in Sencha touch and in my controller I use a function as
facebookComment: function()
{
--------
}
This function is to be called when a button is pressed.
Can any body please throw some light on how to go about this?
i am using following code to post on friends wall see if it is useful to you or not
var postParams = {
method: 'stream.publish'
, target_id: friend_id
, display: 'popup'
, message: message
, user_message_prompt: "Post message!"
}
FB.api(postParams, function(response) {
if(response.error_code || !response) {
to handle error
}
});
or refer this link https://developers.facebook.com/docs/reference/rest/stream.publish/
Well, first you should already be using the Javascript SDK. Then just issue a HTTP POST request to the feed connection of the current user using the FB.api() method with the message field set to your comment:
var body = comment_var;
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
Obviously, should be taking care of the user login status (maybe using the method FB.getLoginStatus()).