How to detect Facebook share success? with Javascript - javascript

This code is sharing facebook but I want How to detect facebook share success How Can I do that with javascript
u = location.href;
t = document.title;
var myWindow = window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
return false;

It seems you should use FB.ui
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.');
}
}
);

Related

How to post an attached link to a facebook group?

How can i post my link attachment to a group feed on facebook with this? I think i've done it wrong.
function post_to_group() {
FB.api("/group_id/feed", 'post', {
message: 'My Sample Post',
attachment: {
name: 'Article Name Slugs',
href: 'http://mylink.com/article-name-slugs/'
}
},
function(response) {
if (!response || response.error) {
console.log('Error occured: ', response.error);
} else {
alert('Post ID: ' + response.id);
}
});
}
here's my reference to what I've done:
Facebook - Posting to a Group page
but this shows an error in both my work and the one i reference to -
{message: "(#200) The user hasn't authorized the application to
perform this action", type: "OAuthException", code: 200}
FB.ui(
{
method: 'stream.publish',
from: myId,
to: groupID,
attachment: {
name: 'Post to a group Test',
href: '...'
}
});

Simple Facebook Javascript post to stream example?

I'm trying to post to user stream, without user prompt. I cannot manage to find a code that works. Facebook JSDK is already loaded and I will insert the code inside:
FB.getLoginStatus(function(response){
to make sure the user is already logged to my application. Could you provide an example of publishing to the user stream using the publish_stream permission?
With Dialog
You need to use the Feed Dialog, with FB.ui():
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: 'Facebook Dialogs',
caption: 'Reference Documentation',
description: 'Using Dialogs to interact with users.'
};
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
Documentation: https://developers.facebook.com/docs/reference/dialogs/feed/
Without Dialog
To make a post without the Dialog you need to use the FB.api():
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
Documentation: https://developers.facebook.com/docs/reference/javascript/FB.api/
Direct URL
https://www.facebook.com/dialog/feed?
app_id=APP_ID&
link=https://YOUR_DOMAIN&
picture=http://YOUR_DOMAIN/image.jpg&
name=Facebook%20Dialogs&
caption=API%20Dialogs&
description=Using%20Dialogs%20to%20interact%20with%20users.&
redirect_uri=http://YOUR_DOMAIN/response
Documentation: https://developers.facebook.com/docs/reference/dialogs/feed/

How to publish something on user's friend stream/wall in an application

In a Facebook application, I need to publish a user's friend stream a mlessage.
how can i figure out of that?
Thanks
send HTTP POST request to the following address https://graph.facebook.com/FRIEND_ID/feed
it returns the ID of posted message on success
here's the example code:
var msg = 'hello world';
FB.api('/YOUR_FRIEND_ID/feed', 'post', { message: msg }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
You can also use the javascript API for posting. The manual has sample code.
https://developers.facebook.com/docs/reference/javascript/FB.ui/
FB.ui(
{
method: 'feed',
to: friendId,
name: 'title',
link: 'http://host.com/title_link.com',
picture: 'http://host.com/image.jpg',
description: 'description',
caption: 'caption',
},
function(response) {
// Check for a posting to wall
if (response && response.post_id) {
// do some logging
}
}
});

facebook jssdk fb.ui picture not showing in dialog

I've got this facebook(and yes-the php variable get parsed into a url correctly)
FB.ui(
{
method: 'stream.publish',
attachment: {
name: 'My Social Status',
caption: 'This Is My Social Status',
picture: 'http://server.com/<?php echo $finalimagepath; ?>',
description: 'My social status lets you create a profile pic that tells your real mood. ',
href: 'http://apps.facebook.com/app'
},
action_links: [
{ text: 'My Social Status', href: 'http://apps.facebook.com/app' }
]
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
</script>
you have to configure the link: parameter for some reason. Not sure how the two are related, and trying to figure out a way to get the picture to show without a link parameter.

How do you autopublish with FB.UI?

I have the stream_publish permission but it still pops up a dialog and there doesn't seem to be any way to pass in an autopublish bool (like it was before the graph api).
EDIT: Also tried offline_access with stream_publish.
Any ideas on how to get this to work?
function streamPublish(imageUrl, imageHref, attachName, attachHref, attachCaption) {
FB.ui(
{
method: 'stream.publish',
message: '',
attachment: {
name: attachName,
caption: attachCaption,
description: (
''
),
href: attachHref,
media: [
{
type: 'image',
href: imageHref,
src: imageUrl
}
]
}
},
function(response) {
if (response && response.post_id) {
//alert('Post was published.');
} else {
//alert('Post was not published.');
}
}
);
}
http://www.takwing.idv.hk/tech/fb_dev/jssdk/learning_jssdk_12.html
The following will autopublish if you have the permissions unlike FB.UI :)
function publishPost(session) {
var publish = {
method: 'stream.publish',
message: 'is learning how to develop Facebook apps.',
picture : 'http://www.takwing.idv.hk/facebook/demoapp_jssdk/img/logo.gif',
link : 'http://www.takwing.idv.hk/facebook/demoapp_jssdk/',
name: 'This is my demo Facebook application (JS SDK)!',
caption: 'Caption of the Post',
description: 'It is fun to write Facebook App!',
actions : { name : 'Start Learning', link : 'http://www.takwing.idv.hk/tech/fb_dev/index.php'}
};
FB.api('/me/feed', 'POST', publish, function(response) {
document.getElementById('confirmMsg').innerHTML =
'A post had just been published into the stream on your wall.';
});
};

Categories

Resources