I am having trouble getting code correct to have user (of my app) post to friend's wall. I want user to be able to pick single friend and post to thier stream. What am I missing to have the user select 1 friend from list, or type friends name? This is my "post" function that I can't get to work. It works when the method is 'feed' to post to the user's wall. But method as 'stream.publish' it still functions like 'feed' and posts to user's wall.
function pubStream(obj,gift_id,item_name)
{
FB.ui({
method: 'stream.publish',
display: 'popup', //have tried display:iframe does same
name: "Special Delivery!",
link: "<?php echo $app_info['transfer_protocol']; ?>apps.facebook.com/<?php echo $app_info['canvas']; ?>/?friendID="+facebook_id+"&giftID="+gift_id,
picture: "<?php echo $app_info['upload_url']; ?>"+obj,
caption: "//not used at this time ",
description: "my item escription",
message: "user's message ",
actions: {"name":"my items name","link":"<?php echo $app_info['transfer_protocol']; ?>apps.facebook.com/<?php echo $app_info['canvas']; ?>/?friendID="+facebook_id+"&giftID="+gift_id}
},function(response){hideLightbox();});
}
It looks like you're looking for the 'send' User Interface.
There are docs on this here:
https://developers.facebook.com/docs/reference/dialogs/send/
It's practically the same code as your feed dialog, except the user can specify which friends they want to communicate it to.
Assuming your code is correct this would work:
function pubStream(obj,gift_id,item_name)
{
FB.ui({
method: 'send',
display: 'popup', //have tried display:iframe does same
name: "Special Delivery!",
link: "<?php echo $app_info['transfer_protocol']; ?>apps.facebook.com/<?php echo $app_info['canvas']; ?>/?friendID="+facebook_id+"&giftID="+gift_id,
picture: "<?php echo $app_info['upload_url']; ?>"+obj,
caption: "//not used at this time ",
description: "my item escription",
message: "user's message ",
actions: {"name":"my items name","link":"<?php echo $app_info['transfer_protocol']; ?>apps.facebook.com/<?php echo $app_info['canvas']; ?>/?friendID="+facebook_id+"&giftID="+gift_id}
},function(response){hideLightbox();});
}
You just choose method: 'send' and then use the properties shown on the 'feed' documentation, here: http://developers.facebook.com/docs/reference/dialogs/feed/
Related
I am trying to send this to facebook and it works except for the title "Some Page Title" is not showing up in the post. Example
The format i am using:
https://www.facebook.com/sharer/sharer.php?u=<url>&t=<page title>
Is passing title not supported any more?
TIA
To overwrite Open Graph meta tags you're only chance is with feed method which requires an app id
JS
$('#facebook-share').click(function (e) {
e.preventDefault();
FB.ui({
method: 'feed', // feed method!
name: 'My title', // overwrites "og:title"
link: 'https://www.facebook.com/Retrogram', // required param
picture: 'http://i.imgur.com/SKwsQM2.png?1', // overwrites "og:image"
caption: 'My caption', // overwrite caption
description: 'My description' // overwrites "og:description"
});
});
Fiddle
I don't want to use the FB like button and apparently "share" has been deprecated.
What I am trying to do is have users click "share"/"post to wall" from my website, and it then places a post on their newsfeed/profile with information on my website/url.
I can't seem to find any code around that will do this- does anyone have an example?
And do they have to connect first? Or can it check if they're logged in, if not, login and it shares automatically?
Thanks!
This is possible in two ways:
You can use the facebook Javascript SDK if you have an app:
FB.ui({
method: 'feed',
link: 'absolute url',
name: 'testtitle',
caption: 'testcaption',
description: 'testdescription',
picture: 'absolute picurl',
message: ''
});
Note that "message" MUST be empty, you can also just remove it.
Without an app (no user can block the app and never get anything from the app anymore, but only possible with popup):
open a popup window with Javascript for the facebook sharer:
http://www.facebook.com/sharer.php?u=<url to share>&t=<title of content>
Note that everything needs to be urlencoded. Of course you can also just use it as a link. And don't forget the og tags in this case.
Edit: Please be aware that "auto sharing" is not allowed on facebook. you have to present the user what you want to share in his name and he has to be able to accept it and add his personal message. would only be possible with an app and an authorized user anyway.
Btw, both methods explained here work without user login/authorization.
Edit2: There is also a "share" method with FB.ui now, to post a link or use Open Graph Actions/Objects.
If you have a dynamic web site as I do, you may strongly want my code.
Note 1: You can't do that if you don't have an app! If you don't have
an app you can simply go to https://developers.facebook.com/apps and
create one.
Note 2: Read my code comments!
Code:
<?
$redirect = "http://www.SITE.com/thanks.html"; //After sharing, you redirect your visitor to thanks.html or just to the home page. Note that the URL given is the URL you set for your app!
$link = curPageURL(); //URL to the shared page (I will give you the function curPageURL() later).
$title = Title(); //Title of the shared page (Note If you don't have a dynamic website you can simply ignore the PHP part)
$descriptionTag = Description(); //Description of the shared page
$pic = Img(); //Image of the post or the logo of your website
echo "<script>
FB.init({appId: \"YOU_APP_ID_HERE\", status: true, cookie: true});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
redirect_uri: '".$redirect."',
link: '".$link."',
picture: '".$pic."',
name: '".$title."',
caption: '".$descriptionTag."',
description: 'You_May_Want_To_Say_Something_About_Your_Web_Site_Here!'
};
function callback(response) {
document.getElementById('msg').innerHTML = \"Post ID: \" + response['post_id'];
}
FB.ui(obj, callback);
}
</script>"; ?>
<a href="#" onclick='postToFeed(); return false;'>Share To Facebook</a>
Note:
Don't forget to set YOUR APP ID in the code!
You need to use the function curPageURL() in order to share the current PHP page!
Code:
<?
function curPageURL() {
$pageURL = 'http';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
Don't forget to declare the function curPageURL() at the beginning of the code I'm giving to you!
I trying to bulid a facebook application using javascript.In my application, the user gets the result and a dialog after a time delay popup. Everthing is working well except one here's my code for the 'post to wall dialog'
<script>
var publish = {
method: 'stream.publish',
display: 'popup', // force popup mode
attachment: {
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
actions: [{ name: 'action_links text!', link: 'http://www.example.com' }],
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.'
),
href: 'http://www.example.com/'
}
};
FB.ui(publish, Log.info.bind('stream.publish callback'));
</script>
The line containing actions not working for me.Can anyone just inform what is the solution for this...
The property should be called action_links not actions and only have text and href values. Use something like:
action_links: [{ text: 'action link test', href: 'http://example.com'}]
Note that the action must be defined through the fb web interface for the app!
I want have feed dialog in which i also want to use his First name or user object.I'm using FB.Ui method.
<script>
var publish = {
method: 'stream.publish',
display: 'popup', // force popup mode
attachment: {
name: 'I visted this Appp',
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.'
),
href: 'http://fbrell.com/'
}
};
FB.ui(publish, Log.info.bind('stream.publish callback'));
</script>
As you can see in caption it is ' i visited this app'.I want to change it to the Facebook user's first name..i.e 'first_name visted this app'..Anyone can help me out
To get info about the user, you would first need to have them authenticate with your application (no extended permissions would be needed as name is considered "basic" information). Then you could then call a FQL query with the javascript api to get their name and then use that to populate the message.
Authenticate user:
<fb:login-button autologoutlink="true"></fb:login-button>
Get users name:
FB.api(
{
method: 'fql.query',
query: 'SELECT name FROM user WHERE uid='+FB.getSession().uid
},
function(response) {
alert(response[0].name);
}
);
I'm making a facebook app and using stream.publish to share something on a wall.
However for the 1) attachemnt link, and the 2) the FB UI action link, when I click either, it will load the page in the same browser window.
I would like to somehow add into these links something like target="_blank" so it opens the link in a new tab.
I know this is possible because when I share a video on youtube it has a target="_blank" on the action link and on the share link.
Does anyone know the trick?
I've tried code like this (I inserted the target blanks) but it doesn't add a target element in the hyperlinks:
FB.ui(
{
method: 'stream.publish',
message: 'Check out this great app! http://apps.facebook.com/{your_app}',
attachment:
{
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.'),
'media': [{
'type': 'image',
'target': '_blank',
'src': 'http://test3.com/test.png',
'href': 'http://test3.com'}],
href: 'http://test2.com',
target: '_blank'
},
action_links: [
{ text: 'Code', href: 'http://github.com/facebook/connect-js' }
],
user_message_prompt: 'Share your thoughts about Connect',
target: '_blank'
}
);
Does anyone have any idea how youtube can accomplish the targets
I believe what you are looking for is
display: 'popup', after method: 'stream.publish'
target is in reference to a fb user_id to post a wall-to-wall