Facebook share in widget - facebook

I have read that the Facebook sharer is deprecated, So I wanted to know how can I create a share button in my widget that will work from any domain (not just the app domain), via the js SDK (Preferably).
For example:
I have my app registered on myserver.com
And someone downloaded my widget on hisservers.com, I want the share to work from there and post to his wall.
How can I do so?

You can use the FB.ui Feed dialog to prompt the user to publish a story on their feed, and specify your link in the function. Like so
function postLink() {
var obj = {
method: 'feed',
link: 'http://myserver.com',
picture: 'a_picture',
name: 'My Server',
description: 'Sharing MyServer from HisServer.'
};
function callback(response) {
console.log(response['post_id']);
}
FB.ui(obj, callback);
}
Of course you'll have to also include the proper initialization for the JS SDK.

function postLink() {
var obj = {
method: 'feed',
link: 'http://myserver.com',
picture: 'a_picture',
name: 'My Server',
description: 'Sharing MyServer from HisServer.'
};
function callback(response) {
console.log(response['post_id']);
}
FB.ui(obj, callback);
}

Related

facebook no button for share in fb official application

http://s-nowproject.ru/GREET-7D841B7FB2E6E912B1B35B3B112545F7 - example
When someone try share with facebook, all ok.
But when share with Iphone 5/6 there is no share button, because link open official app without share button.
Only preview.
Is it problem with facebook app?
What I see:
What I want:
Not working variant, but without errors, and without button for share:
FB.ui({
method: 'share',
href: getUrlA(this)
}, function (response) {
});
Working variant:
FB.login(function(response) {
FB.ui({
method: 'share',
href: getUrlA(this)
}, function (response) {
});
});

Facebook sharing: going from 'feed' to 'share_open_graph'

I'm messing around with an Angular app, let's say for the sake of argument that I'm not using any meta tags, how can I use the Share Dialog to let users share pages of my app?
Using the old Feed Dialog works, but it has been deprecated:
$scope.share = function() {
FB.ui({
method: 'feed',
name: 'This is the name field',
link: 'The link',
picture: 'The picture',
caption: 'The caption',
description: 'This is the content of the "description" field, below the caption.'
})
},
function(response) {
if (response && !response.error_code) {
console.log('Posting completed.');
} else {
console.log('Error while posting.');
}
});
};
So even though this works, I want to use the Share Diolog in the same way but I'm not figuring it out. This is sort of what I've been trying, keep in mind that I'm a newbie:
$scope.share = function() {
FB.ui({
method: 'share_open_graph',
action_type: 'og.likes',
action_properties: JSON.stringify({
object: {
'title': 'The title',
'image': 'An image',
'url': $scope.shareUrl,
'description': 'This is the description',
}
})
},
function(response) {
if (response && !response.error_code) {
console.log('Posting completed.');
} else {
console.log('Error while posting.');
}
});
};
Any hints?
The short answer is that you can't, you must use OpenGraph meta tags.
Since Facebook doesn't understand JavaScript and thus Angular, you must detect Facebook's crawlers server-side and render a static page for them instead of the Angular app.
While the precise implementation will vary depending on your server technologies, here's the general idea:
Setup a route for the resources that need sharing: http://example.com/resources/:id
Look for the user-agent
If it's one of Facebook's crawlers, fetch the resource and render a simple view with OpenGraph tags and an empty body. Otherwise, simply render the Angular app.
Facebook's crawlers are available here and they currently are:
facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
facebookexternalhit/1.1
Facebot

FB.UI using imaging staging

I have a standard file-upload form, which I want to use to collect a user's image and than upload to Facebook.
If I post the upload form to the FB 'staging' url, I get the encoded staging reference - but when I try to launch a FB.UI() feed dialog, supplying the staging token as a "picture" parameter it fails?
Is the staging URL strictly for use in creating a graph object w/o using the dialog? And if I want do use the dialog do I have to upload the image somewhere else and than reference it ?
Here's my example:
$('#picture_upload').submit(function(e){
e.preventDefault();
$(this).attr('action',$(this).attr('action')+'?access_token='+accessToken);
$(this).ajaxSubmit({
success: function(response){
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
picture: response.uri,
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
} //call function after success
});
});
The response contains something like:
{"uri":"fbstaging://graph.facebook.com/staging_resources/MDAxMDE1MTU3NjIyNzExNzYwNA=="}
Which is obviously invalid as a picture parameter in the FB.UI function

facebook api with private message multiple to (friends)

I development facebook private message for invite with facebook api.
<script>
FB.init({ appId: 'xxxxxxxxxx', xfbml: true, cookie: true });
FB.ui({
method: 'send',
to: ['1736383768','590528674'],
// picture: 'http://thinkdiff.net/iphone/lucky7_ios.jpg',
//Can be page, popup, iframe, or touch.
display: 'popup',
name: 'yyyyyy',
link: '<%=Request.QueryString["link"]%>'
});
</script>
but adds only the first mate.
how to multiple friends send private message ?
var publish =
{
method: 'stream.publish',
message: 'Some kind of test',
uid: uid,
attachment: {
name: 'Test',
caption: 'Facebook API Test',
description: ('Sure hope it worked!'),
href: 'http://www.test.com/',
media: [
{
type: 'image',
href: 'http://test.com/',
src: 'http://test.com/image.jpg'
}
]
},
action_links: [
{ text: 'Your text', href: 'http://www.test.com/' }
],
user_prompt_message: 'Share your thoughts about test'
};
publish.target_id = friendID;
FB.ui(publish);
publish.target_id = friendID;
FB.ui(publish);
return false;
You should not use stream.publish.
As said by facebook : "We are in the process of deprecating the REST API, so if you are building a new application you shouldn't use this function. Instead use the Graph API and POST a Post object to the feed connection of the User object"
So, now you have the send and feed methods left.
You cannot fill the send method with more than one user id (you can only if you are whitelisted by facebook, but I'm not quite sur how to do this , I would not count on it either).
You can use the feed method to post on many user's friends wall with something like this
FB.api('/USERID/feed', 'post', {
name:postName,
link:postLink,
picture:postPicture,
description:postDescription,
message:postMessage
}, function (postResponse) { //DO SOMETHING HERE });
But doing it, you are taking the risk of your app being deleted by facebook if someone flag it as spam.
As far as I know, sending messages to multiple friends via an App is considered bad/spam by facebook so they do not allow this anymore.
You still can Invite as many friends as you want via the App request dialog (method apprequests) but I'm not sure this is what you want.

using facebook stream publish

I want to publish a URL as an attachment to a friends wall:
var attachment={'name':'favor','href':'http://128.196.239.71/movie.php?mid=<?php echo $_GET['mid']; ?>'};
Facebook.streamPublish('',attachment,null,friends[i],comment,callback);
Doing the above gives me a Facebook undefined, what should I do to remedy this?
Do I need to set a special permission in order to do this to the sender of this message?
You do need the stream.publish permission in order to use the stream.publish method or the equivalent graph API call.
You can check that the user has already granted this permission with something like this:
FB.getLoginStatus(function(response) { if (response.perms) { /* check perms */ } })
You can request the permission with something like this:
FB.login(function(response) { /* check perms */ }, {scope: 'publish_stream'})
Then in the response you can check to see if it was actually granted, then you should be able to do stream publish calls.
However, I don't recognize the format of your call "Facebook.streamPublish". I think the new API requires you to do a call more like
FB.api({method: 'stream.publish', message: 'hello'}, function(response) {})
Alternatively to all this, you can use the dialogs API to create a post and show it to the user, and have them approve it or disapprove it. This does not require the stream.publish permission. Something like this (the example given in the FB.ui API docs):
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.');
}
}
);
At the rate Facebook changes, I hope some of this information is still accurate by the time you read it (or even accurate to begin with).