I am working on one of my pet projects. Where one of the features I need is as follows:
User clicks the “share to Facebook” button on my web page, as done here https://developers.facebook.com/docs/plugins/share-button/
And then in Facebook popup window, user can either click “post/submit” or cancel or close the window. Is there any way to know that user did really post to his/her Facebook timeline?
Please assume, that user is not my friend or have never liked my page, but user is currently logged in to Facebook in another browser tab.
I see FB events, those can be captured in callback at https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ , e.g. edge.create can capture like button.
Similarly is there any way to capture “share/post to fb” ?
I do not believe that you can do this with the share button.
You can however, initiate the same dialog using the JavaScript SDK. Using the SDK, you'll be able to capture the callback function that you mentioned.
Here is the example given in the documentation:
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.');
}
}
);
The answer provided by Lix doesn't work anymore. The UI methods have changed, now this would be the Share Dialog (not Feed), which only returns the post object if "the user is logged into your app using Facebook and has granted publish_actions."
https://developers.facebook.com/docs/javascript/reference/FB.ui
As far as I've found, there's no event to subscribe to for post sharing.
Related
I am working on a web app using AngularJs as front-end and Laravel as back-end
In many views I have sharing bar with tweet button, I managed to add a share button using twitter javascript widget
twttr.widgets.createShareButton(
'https://dev.twitter.com/',
document.getElementById('tw'),
{
count: 'none',
text: 'Sharing a URL using the Tweet Button'
}
).then(function (el) {
console.log("Button created.", el);
});
and also I managed to detect the click event on this twitter share button via
twttr.events.bind(
'tweet',
function (event) {
console.log('tweeet', event);
}
);
but this event fires if user clicked on tweet button even if he just closed the popup and didn't tweet !!
I found this thread https://twittercommunity.com/t/need-to-check-if-user-tweet-like-retweet-post-successfully-using-js-intent/61432 on twitter community but it has been since Feb,2015 I hope there is something new after more than one year !
Is there anyway to track a complete successful tweet!!
Thanks in advance.
If you want to know the users geolocation in a web browser you have to use the html 5 api. When calling the function:
navigator.geolocation.getCurrentPosition(success)
a dialog pops up, asking the user if he want to share the location or not. My question is, is it possible to know when the user clicked confirmed. I want to display a loading spinner on a html page after the user has clicked the confirm button. (To get the location can take some time on a mobile, and i don't want the spinner to show before he has pressed the confirm button, as he can get confused )
Have you tried this code? You can add Callback functions, and within them handle user responses.
navigator.geolocation.getCurrentPosition(successCallback, errorCallback {maximumAge:600000});
function successCallback(position) {
// Handle Confirm button hit
}
function errorCallback(error) {
// Other
}
navigator.geolocation.watchPosition(function(position) {
//Succes Code
},
function (error) {
if (error.code == error.PERMISSION_DENIED)
//Code when permission is not granted
});
I am not sure, that mobile will respond well to this, but it works on PC.
No you can't. when your geolocation code executes, the request goes to browser and then browser asks to user for confirmation. If user accepts, then the request goes forward else it will drop. so you will not get any confirmation whether user clicked on accept button or not. but you will get whether user denied or not by using error PERMISSION_DENIED
I've a question about the popup post of my application.
Basically the application create an image.
There is a button, once it's clicked an ajax call is done, with ImageMagick it is created the image, then the code returns to javascript that calls postImage() function, that opens the popup for posting to a friend profile the image.
Is there a way to prevent this popup to be blocked?
Which approach / solution should I take?
function postImage(sIdFriend, sIdPostcard, sPathPostcard){
var hFacebookData = {
method: 'feed',
to: sIdFriend,
display : 'popup',
link: 'https://apps.facebook.com/MY_APP/',
picture: 'https://fb.thesecretpages.nl/MY_APP/image.png',
name: 'MY_APP_NAME',
caption: 'MY_APP_CAPTION',
description: 'MY_APP_DESCRIPTION'
};
function callback(response) {
window.parent.location.href = "https://apps.facebook.com/MY_APP/?st=4";
}
FB.ui(hFacebookData, callback);
return false;
}
At the end, the only way is really to call immediately the popup and after that make the ajax call, so while the user deal with the popup and posting it is redirected to the timeline of the friend, the ajax operation goes on and is executed.
the ajax call provoke the blocking of popup.
i read about it on stackoverflow for login popup, it's the same for posting popup too.
Not quite sure how to explain this the best way, but i'll give it a go!
I have a php site that uses Fancybox. At the moment, if anyone clicks Login, an overlay appears with the login form. If someone clicks to post a new listing and they're not logged in, I'd like the fancybox overlay to appear again, allowing a user to login.
At the moment, I have a couple lines of php code that check if a session is active - if not, it redirects to a login page, I want this to activate a fancybox popup with the login form... if possible?
I'm not sure how best to achieve this? Any help would be awesome! :)
I'm not sure what programing language you are writing in besides jQuery, but a high-level solution might be to drop a cookie when the user logs in. Then, when they click to post a new listing, check for that cookie. If it's there, let them post. If not show the login window. Here's some pseudo code using the jQuery.Cookie plugin:
$(function(){
$('.login-button').click(function(){
//send login info via ajax
$(this).hide("slow",function(){
// drop a cookie
$.cookie( 'login', '1', { expires: 1, path: '/' } );
});
});
// When the post button is clicked, check for the cookie
// If there's no cookie, show the login box
$('.post-button').click(function(){
if( $.cookie('Login') === null ) {
$("#login-box").fancybox();
} else {
// do nothing
}
});
});
There can be multiple ways of doing so.
First of all, how are you identifying that someone is logged in? Suppose if I can do so with an if condition:
if(user==null) {
//no login
}
I can trigger the click of anchor link for LOGIN and thus, open the fancybox again.
if(user==null) {
$("a#login").trigger('click');
}
Hope it gives you some help.
The below code works perfectly.. On clicking the fb:login-button, it posts the message on facebook wall of the person who has logged in.
But, i want this to happen immediately after the page loads and not after clicking the button. If the user is logged In already, the message should be posted on wall. How can i do this ?
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#appId=XXXXXXXXXXXXXXX&xfbml=1"></script>
<fb:login-button show-faces="false" width="200" max-rows="1" perms="publish_stream" onlogin="postonwall()">Click to Publish Below Content</fb:login-button>
<script>
function postonwall()
{
FB.api('/me/feed', 'post',
{
message: 'A good reference for APIs',
link: window.location.href,
name:'API Reference',
picture:'http://www.demo.lookmywebpage.com/publish-on-facebook-wall/Google-Twitter-Facebook.jpg',
description:'Demo Facebook Post'
}, function(response) {
if (!response || response.error) {
alert('Oops! User Denied Access');
} else {
alert('Success: Content Published');
}
});
}
</script>
But, i want this to happen immediately after the page loads and not after clicking the button.
So you want to annoy your users …?
If the user is logged In already, the message should be posted on wall. How can i do this ?
Use FB.getLoginStatus, and if the user is already connected, then make the post.