I am using FB share and like plugin on my website. Link below:
https://developers.facebook.com/docs/plugins/like-button
I would like to track a user who logged in on my website (I have the user id) and liked and shared a post through FB like and share plugin and when the user does then I would do some php coding and reward the user right after the fact that the user likes and shared my post. How am I able to track user like and share?
Thanks,
Read this -
https://developers.facebook.com/docs/javascript/reference/FB.ui
The example there is pretty clear and you have a callback in which you can do whatever based on the state of the response (they actually shared, they cancelled etc.), you can call your PHP-powered server in the callback and do whatever.
You cannot get the share callback using this like button. You can instead create a share button of yours and invoke the Feed Dialog on its click-
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
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.');
}
}
);
Also see this link: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSocial
Related
I'm building application have function when use share on facebook they will get
point from this action. By check this, I will check if facebook response post_id
but it return empty for me event user logged in app like with scrope
"publish_actions". I searched around but I cant see any thing help? This is my
code
FB.login(function(response) {
if (response.authResponse) {
console.log(response)
FB.ui({
method: 'share',
href: url_here,
}, function(response) {
console.log(response);
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, { scope: 'publish_actions', return_scopes: true });
Any suggestions?
Thanks.
What you are trying to achieve is not allowed and not possible. You will never get publish_actions approved for this, because you must not reward users in any way for sharing something. You need to read the platform policy: https://developers.facebook.com/policy/
4.5: Only incentivize a person to log into your app, enter a promotion on
your app’s Page, or check-in at a place. Don’t incentivize other
actions.
I've just find the issue. I used old app Id that I build before. So I create new facebook app and point it to current website I'm building. It's work perfect
Thanks guys for rep
I have a page where you can share something.
First im logging in with FB.login()
FB.login(function(response) {
if (response.authResponse) {
sharePost(imgName,socket);
} else {
//do nothing if not logged in....
}
}, {scope: 'public_profile,email,user_friends'});
Then im using the following share
FB.ui(
{
method: 'feed',
link: 'myurl',
caption: 'mycaption',
display:'popup',
title: 'title,
picture:'myimg.png',
description:'mydescription,
name:'myname'
},
// callback
function(response) {
if (response && !response.error_code) {
if(waitedTooLong == false)
{
successfullLogin(socket);
}
console.log("shared");
} else {
successfullLogin(socket);
console.log("not shared");
}
}
)};
Sometimes it blocks the popup after logging in. Sometimes not.
I thought about removing FB.login() but I need the scope for other actions.
You need to use FB.ui dialogs on user interaction (= mouse click), not in the asynchronous callback function of FB.login. Modern browser detect it as unauthorized popup and block it. Also, it´s a bad idea to present a feed dialog right after authorization. Present a Login Button and use FB.login, then present a Share Button and use FB.ui feed or FB.ui share.
Btw, you don´t even need to authorize the user for FB.ui, so you can just skip FB.login and use it when you really need it.
When sharing some links on facebook(either programatically or manually), javascript code is being shown in the post.
Thus my question is more related to how to fix my website, so that, when posting link to facebook, javascript code doesn't show in the facebook post.
Forexample try posting this link:
http://djuice.com.pk/discounts
You'l see javascript code(which is present on the shared page) in the facebook post.
You are should set description param for sharing button. For example:
FB.ui(
{
method: 'feed',
name: 'The Facebook SDK for Javascript',
caption: 'Bringing Facebook to the desktop and mobile web',
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: 'https://developers.facebook.com/docs/reference/javascript/',
picture: 'http://www.fbrell.com/public/f8.jpg'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I am trying to make a web page to post status in facebook but with scripts on FB webpage I am not able to do it.
<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
Post To Wall
<script src="//connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId: 'XXXX',
status: true,
cookie: true,
xfbml: true,
oauth: true });
function postToWall() {
FB.login(function(response) {
console.log(response);
if (response.authResponse) {
FB.ui({
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://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.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
});
} else {
alert('User cancelled login or did not fully authorize.');
}
}, {scope: 'user_likes,offline_access,publish_stream'});
return false;
}
</script>
</body>
</html>
Of course I use the correct appId of my application. I have the applicacion in sandbox mode because I still has nothing, just this script. My webpage will just has this part to post and nothing else related to facebook.
I am testing it in my compunter with xampp. So I guess in facebook app domain I have to write it but everything I tried (localhost, localhost/faceapp/...) fail. For example, I get this:
Error
App Domains: http://localhost/appFace should not contain protocol information.
When the prompt appears, you can write your user and your password but the next window tells you that the webpage is not allowed in app configuration and something else. I read it in spanish so I don't know the exact sentence in english.
I have found many answet about this but most of them are from the previous version of the api ¨(which has changed since that) and the others tells to use localhost or so, and I can't save the changes in fb app writing that.
In your app settings in FB, put App domain "localhost" and if your are using Login With FB, then in Site URL enter http:// localhost / (without space) or if you have created any virtual host, enter that...
I am currently in the process of developing a canvas application that will make use of the social plugins provided by Facebook.
The application itself allows a user to create a text file from a form, download it if they wish and also post the file to their feed using the Feed Dialog.
I have implemented the Feed Dialog and it works fine, but the problem I am getting is that if the user clicks the cancel button from the dialog that prompts them to share the file or cancel, a message is displayed on my page stating that post was successful when it did NOT post to facebook.
How can I alter this to display a message stating that the file was not posted to their feed?
Here is the js code.
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
link: 'http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
picture: 'http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
name: 'Game Configuration File Creator',
caption: 'Call of Duty 4: Modern Warfare',
description: 'config_mp.cfg',
redirect_uri: 'https://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
};
function callback(response) {
document.getElementById('msg').innerHTML = 'Post was successful.';
}
FB.ui(obj, callback);
}
You have to check wether the response was valid or not in your callback.
function callback(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}