Using FB.ui to post to Page wall - facebook

I'm using FB.ui to post to a Facebook user wall. However, I am uncertain on which parameters to use to post to a Page or Application wall. Any links?
I am trying to post to the Page wall as that page, not as the user's account.
Code to post to user account:
FB.ui(
{
method: 'feed',
name: name,
link: link,
picture: picture,
caption: caption,
description: redemption,
message: message
},
function (response) {
if (response && response.post_id) {
alert(response.post_id);
} else {
}
}
);

Got it:
you have to set the to and from values:
FB.ui( {
method: 'feed',
name: name,
link: link,
picture: picture,
caption: caption,
description: redemption,
message: message,
to: page_id,
from: page_id
},
function (response) {
if (response && response.post_id) {
alert(response.post_id);
} else {
}
}
);

I used the JavaScript SDK to post on user's wall:
function graphStreamPublish(){
var body = document.getElementById("txtTextToPublish").value;
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
When I go through the Graph API Page I think if you change '/me/feed/' to 'pageId/feed' then it may post the message in that page. I am not sure. - just a suggestion.

To share on a friend's wall, as of February 2012:
FB.ui({
method: 'stream.publish',
app_id: appId,
display: 'iframe',
name: name,
link: link,
picture: picture,
caption: caption,
description: description,
target_id: friendIds
});

To post to facebook wall use the following.. .
Call the below js function using simple call as in below
Post to Wall image/text?
//facebook: post to wall
function publishWallPost() {
FB.ui({
method: 'feed',
name: 'Your App Name',
caption: 'Caption Text',
description: 'Your description text',
link: 'https://www.facebook.com/link/link.link',
picture: fbImg
},
function (response) {
console.log('publishStory response: ', response);
});
return false;
}
window.fbAsyncInit = function () {
FB.init({
appId: 'Your App ID',
status: true,
cookie: true,
xfbml: true
});
};
(function () {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());

Sorry, this is an old question, but I thought this might be helpful for people who find it via google.
http://fbmhell.com/2011/07/facebook-share-popup-iframe-tabs-jquery/

Just remember target_id needs to be parsed into an int. The response["to"] comes back as a string.

Related

How to hide facebook post link/caption parameter from facebook javascript sdk

I'm using Facebook JavaScript SDK to post on different Facebook's users Pages, from my custom HTML form,
My HTML FORM contains Following fields
title=>textbox,
Link url=>textbox,
picture=>textbox,
message=>textarea
but the issue I'm facing is that when user did not entered LINK URL in field(blank), and entered Picture URL in picture URL fieldbox then facebook showing PICTURE HOST name in wall instead showing blank or no link URL / picture URL.
CODE which I am using for post my status on pages
FB.api('/' + d + '/feed', 'post', {
message: my_message,
link: url,
name: title,
picture: picUrl,
description: desc,
access_token: b.access_token
}, function (a) {
if (!a || a.error) {
alert('Error occured')
} else {
alert('Message Posted Successfully.')
}
})
link: url
picture: picURL
I tried to submit by comment "link" parameter but still facebook showing picture host URL address on wall.
so i need to know how to stop showing picture host URL address on wall if user did not submit link URL
In the Facebook post you can refer this link as an Caption you just need to keep some space into the Caption Parameter. If you are using string.empty then it will print the you IP Address/Domain Name.
Here i am providing you the sample Code for that...
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
//Get your Facebook API Key from Web.config
appId: '<%=ConfigurationManager.AppSettings["FB_API_KEY"].ToString() %>',
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
};
(function () {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
you need to create div to add the script into it.
Now, I am Calling the postToFacebook() function from the ServerSide, you can do that as per your requirement. So, Here is the function of that.
function postToFacebook() {
var POST_NAME = "Post Name";
var POST_DESCRIPTION = "Post Description";
var POST_MESSAGE = "";
//Here I am Leaving some space in the Caption to avoid link name
var POST_CAPTION = " ";
var body = 'Reading Connect JS documentation';
FB.login(function (response) {
if (response.authResponse) {
FB.api('/me/feed', 'post', { body: body, message: POST_MESSAGE, caption: POST_CAPTION, name: POST_NAME, description: POST_DESCRIPTION, picture: document.getElementById('hfImageURL').value }, function (response) {
if (!response || response.error) {
//alert(response.error);
alert('Image is not posted.');
} else {
alert('Image is posted.');
}
});
}
}, { scope: 'offline_access,publish_stream' });
}
I am storing the Image URL into the HiddenField having ID hfImageURL, and give that to the picture property of the Post.
So that's it you can check that code... Working fine for me...
Have a Nice DAY...

How can I post feed to other user wall by javascript sdk

I've succeed to publish feed to my wall but not to another user wall
I've defined both 'from' and 'to' variable
but I got error message when publishing the feed which said
"An error occurred. Please try again later."
here is my code when publishing
var obj = {
method: 'feed',
link: 'http://apps.facebook.com/' + fb_app_id,
picture: app_url + 'icon/test.png',
from: facebookid1,
to: facebookid2,
name: 'Test App',
caption: 'This is a test!!',
description: 'Test to publish feed to other user wall'
};
function callback(response) {
// Callback after feed posted...
}
FB.ui(obj, callback);
I don't know what is wrong or their are any extend permission required ?
try this code
FB.ui( {
method: 'feed',
name: name,
link: link,//Link is any link you want to post
picture: picture,
caption: caption,
description: redemption,
message: message,
to: page_id,
from: page_id
},
function (response) {
if (response && response.post_id) {
alert(response.post_id);
} else {
}
}
);
also if a user have set privacy that no once can post anything on their's wall, you'll unable to post in this case

API Error Description: Session key invalid or no longer valid (error 102)

I cant figure out why facebook publish is not working on this site
I get
API Error Code: 102
API Error Description: Session key invalid or no longer valid
Error Message: Iframe dialogs must be called with a session key
While calling the stream.publish method as iframe
<script type="text/javascript">
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/fr_FR/all.js';
document.getElementById('fb-root').appendChild(e);
}());
window.fbAsyncInit = function()
{
FB.init({ appId: '303380259758621',
status: true,
channelUrl: 'http://www.crabegame.com/channel.php',
cookie: true,
xfbml: true,
oauth: true});
}
function PublishStream(score)
{
FB.ui(
{
method: 'stream.publish',
display : 'iframe',
message : '',
attachment:
{
name: 'CrabeGame',
caption: 'Essaye de battre mon score sur le Crabe Game !',
description: "J'ai réalisé un score de " + score + "points au Crabe Game !",
href: 'http://www.crabegame.com',
media:
[
{
type: 'image',
src: 'http://crabegame.com/media/crabe_fb.png',
href: 'http://www.crabegame.com'
}
]
},
action_links:
[
{
text: 'Play Crabe Game',
href: 'http://www.crabe-game.com'
}
],
user_message_prompt: 'Publier sur votre mur'
},
function (response)
{
if (response && response.post_id)
{
}
}
);
}
</script>
This means that you have no current user. Try this in order to call PublishStream:
FB.login(function(response) {
if (response.authResponse) {
PublishStream();
} else {
console.log('Not logged in');
}
});
you don´t need a logged in user, just remove display: "iframe", worked for me. it will still show in an iframe, but without error. don´t ask me why, with 1:1 the same app settings it works WITH the display value in another app of mine...at least that worked for me with the apprequest dialog, might be the same here.
and i would use "feed" instead of "stream.publish".
see here: https://developers.facebook.com/docs/reference/dialogs/feed/
also: Using Like Button and FB.ui (apprequests) On the Same Page Conflicts

Facebook wall post response is blank screen in webview stuck in XD_proxy.php

I'm trying to post on facebook wall from Webview, its showing popup
to share content but after cancel or post it doesn't get back to
home share screen or unable to dispose popup window. The same
implementation is working fine in Browser, but not working in
Webview.
After sharing or cancel it should get back to share screen, but it
doesn't get back to the share screen and stuck in XD_proxy.php auth
link of facebook
Here's my code.
window.fbAsyncInit = function() {
FB.init({appId: "App_id", status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement("script"); e.async = true;
e.src = document.location.protocol + "//connect.facebook.net/en_US/all.js";
document.getElementById("fb-root").appendChild(e);
}());
function streamPublish() {
FB.ui(
{
method: 'stream-publish',
display: 'iframe',
message: 'getting educated about Facebook Connect',
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
link: 'http://www.fbrell.com/',
picture: 'http://www.fbrell.com/f8.jpg',
actions: [
{ name: 'fbrell', link: 'http://www.fbrell.com/' }
],
user_message_prompt: 'Share your thoughts about RELL'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}

Publish on users facebook wall

The users of the website I'm building should be able to publish a title, a picture and a link on their facebook wall.
I found many questions on the subject, but no decent answer...
The easiest way I've found is to use the JavaScript SDK:
http://developers.facebook.com/docs/reference/javascript/
http://developers.facebook.com/docs/reference/javascript/FB.ui/
Load it up:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: 'your app id', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
Use the FB.ui method in your JavaScript file (fill in your data accordingly):
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'http://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
message: 'Facebook Dialogs are easy!'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);