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.');
}
}
);
Related
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
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.
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 have created an invite friends code, which is properly working if an FB user is logged in.
If I remember correctly, it also worked, when there were no active fb users, in this case it simply shown a fb login page and then it went to an invitation.
Currently the 'invite facebook friends' link is really struggling, if there aren't any active facebook users.
FB.ui({
appId: '"' + appId + '"',
method: 'apprequests',
display: 'iframe',
message: '"' + message + '"',
title: 'Send your friends an application request'
},
function (response) {
if (response && response.request_ids) {
FB.api(response.request_ids, 'delete');
}
});
Did I do something wrong, or is this a bug in the Facebook invitation?
It seems, I got an answer on the Facebook bug site. However, it should help anybody , who has a lack of FB api knowledge . The documentation didn't show this example:
If there aren't any active fb session , it just open a login screen.
Finally I just realised what happened:
It doesn't show a login screen , if you use an IFRAME.
Do not use that!!
Thank you for Noorin Ladhani.
<script>
document.getElementById('send-to-many').onclick = function() {
FB.ui({
method: 'apprequests',
message: 'Visit my page'
}, Log.info.bind('send-to-many callback'));
}
</script>
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.');
}
}