Increase variable if an action has happened - javascript

I am currently working on a website, on this website I have a Facebook share button and a Twitter tweet button. Then I have a javascript variable set to 0, now the problem I am having is that I would like to check if a person has shared on Facebook and made a tweet on Twitter by increasing the variable by 1 for when sharing on Facebook and increasing by 1 when tweeting and then if the variable is 2 then I would like to create a pop up.
I have gotten this which is the Facebook button
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/da_EN/sdk.js#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
Then I have the tweet button
<div id="twitbut">
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
And lastly the Javascript variable which I have in the same html script
<script type="text/javascript">
var shares=0;
if (shares == 2)
</script>
My issue is that I am not really sure how to check if a person has shared on Facebook or Twitter, but I would think I have to get the variable in the button codes and then when a person clicks that button it would increase the variable. But then if I were to do it like this, wouldn't you just have to click the button and then the person doesn't have to share the actual post? which is kind of the goal.
I am sorry if it is a bit cluttered, but in simple what I want to do is ask the user to share on both Facebook and Twitter and if the person does this they are rewarded with a coupon code. This code would then be in a pop up.
Thanks in advance.

The method based on subscribing to the click event on the buttons is not reliable. You absolutely do not know if the user did or didn't like your page.
If you do it for business purpose, please stop!
The only safe way to know if the user did like your page is by having him authenticate via facebook/twitter, then ask their apis.
I think you should take a look to :
https://developers.facebook.com/docs/graph-api/reference/user/likes/

Related

auto share and send current webpage url with only one person(friend) on click of messenger button on webpage using javascript

i am testing facebook send button for my website and wants users to send current webpage url link to admin directly by clicking on facebook messenger button..here are javascript codes
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '95100348886',
xfbml : true,
version : 'v2.6'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-messengermessageus"
messenger_app_id="95100348886"
page_id="XYZ"
color="blue"
size="large">
</div>
that was the above javascript code which i have used (you can put your page name instead of "xyz"...
and below is the html code
<a href="https://m.me/XYZ">
I am sending the link to admin which I liked
you can put your facebook page name instead of "xyz"
now these codes open direct messegner and allows user to chat with admin and users are allowed to send message to the admin via this button of facebook messenger.
now i want to load default text when the messenger opens so that user dont need to type anything and can directly click on send button to send the default message along with current page url.
here is one code on which when user click it by default shares current page url but it allows user to select from the contact which i dont want as user should compulsorily send the message to admin only .
<div class="a2a_kit a2a_kit_size_32 a2a_default_style">
<a class="a2a_dd" href="https://www.addtoany.com/share"></a>
<a class="a2a_button_facebook_messenger"></a>
</div>
<script async src="https://static.addtoany.com/menu/page.js"></script>
hence i want "auto share and send current webpage url to only one person(friend) on click of messenger button on webpage". which is the mixture of above codes
thanks in advance

Send FB Private Message to multiple people using Facebook API

I would like to send private message to multiple people using FB API, but I want it to received by the recipients individually not as group message, this is the code given by fb:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-send" data-href="http://developers.facebook.com/docs/plugins/" data-colorscheme="light"></div>
this is how it looks like:
I found this code but it seems outdated or deprecated by fb
FB.ui({
method: 'send',
to: sendUIDs,
name: "xxx",
description:'xxx',
link: 'http://www.mysite.com',
});
what I want to achieve is make a fb message notif to my website users,
any idea guys how to achieve it? is it even possible?
thanks!
I only can do it with images. Send the picture to your self, click on the picture, on the bottom right click on forward. Facebook will show you a list of friends with boxes where you can choose the recipients you want to "Forward in separate messages"
P.S. You make want to take a screen picture of your text in order to "Forward [the message] in separate messages"
I hope it helps.

How to show facebook like button even if user isn't logged into Facebook?

Currently, the code <div class="fb-like" data-href="https://facebook.com/myappurl" data-send="false" data-width="450" data-show-faces="false"></div>
Only shows the like button if I am logged into Facebook in the browser. How do I get it to display even if the user is logged out?
Like wordpress.org for example...See the bottom left hand corner of the page.
Thanks in advance!
Best,
Alex
The only situation where a like button will not show up (assuming it has been implemented properly) is if the page that is to be liked is a Facebook page that has a restriction placed on it. This includes country and age restrictions. If your Facebook page has a restriction, the user needs to be logged in to Facebook so that the user can be verified as to be allowed to see the like button.
It displays regardless of whether a user is logged in or not. If the user is not logged in and clicks on Like, they get a popup that says
"You must log in to see this page."
Are you sure you're including the fb-root div and the Javascript?
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=Your-App-ID-HERE";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

share button without app id

Can i have a facebook share button without an app id? I have a facebook page, not an app and no associated app.
i have a div
<div class="fb"></div>
and the js file
$('.op-blackfb').click(postToFeed);
var postToFeed = function() {
var share = {
method: 'feed',
u: 'http://mylink.goes/here'
};
FB.ui(share, function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
});
}
This used to work, but now it fails with an error in the popup dialog, i'm guessing after facebook changed the API. Does anyone know a workaround for this? I want to have a custom share button? I have the normal fb share button, but i want to have an image that doesn't break the design.
This works without an app id but has the standard fb button
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/de_DE/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
<div id="fb-root"></div>
<p id='msg'></p>
<fb:share-button type="button" style="display:inline-block;" share_url="http://my.link/here"></fb:share-button>
Thank you,
How about a modal iframe? You can use facebooks sharer. You can use any button you want to open up the dialog. The problem is that this uses a facebook page, so you have to merge it into you design with some iframe or you must use a popup
https://www.facebook.com/sharer/sharer.php?u=[the-link-you-want-to-share]
Also facebooks documentation is also very well done
https://developers.facebook.com/docs/reference/dialogs/feed/

Facebook Plug-in Facepile Issue

I'm having trouble with understanding the basics of the Facepile plug-in for Facebook developers. I've successfully got Facepile up and running and displaying a picture of someone who 'likes' the page, as long as they're a friend.
That's all good. But there's another feature of Facepile that I just can't get working. And that's to simply display how many people have liked the page. On the Facepile developers page it says:
If some users have liked your page, but none of the viewing users friends have liked it, the plugin will display the total number of users who have liked your page.
However, this simply just doesn't show up for me. Is there something I might be missing? Here's my code as it appears:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=00000000";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<script src="http://connect.facebook.net/en_US/all.js
#appId=0000000000000&xfbml=1"></script>
<div class="fb-like" data-href="http://myurl" data-send="false" data-width="450" data-show-faces="true"></div>
<div class="fb-facepile" data-href="http://myurl" data-action="watch" data-max-rows="1" data-width="300"></div>
Bare in mind that I replaced the App ID and URL with dummies. An insights you might have will be hugely appreciated!
Update: After reading your question carefully, I'd recommend you to try the IFRAME version once to see if that works for you.
<iframe src="http://www.facebook.com/plugins/facepile.php?href={SITE_URL}&size=small&width=292&max_rows=1" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px;"></iframe>
Old Answer:
You don't need facepile, assuming "like count" is the only thing you need. Simply use Open Graph for it.
Open Graph:
https://graph.facebook.com/{PAGE_ID}
eg. https://graph.facebook.com/314467614927
Returns:
{
"id": "314467614927",
"name": "Angry Birds",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/276791_314467614927_795266395_s.jpg",
"link": "http://www.facebook.com/angrybirds",
"likes": 20292918,
...
}
Now retrieve the like count from the JSON, and populate it wherever you wish to display it using JS.

Categories