Binding Dynamic URL to FB like Button in angular2 - facebook

I am trying to bind Dynamic URL to facebook page like button like this
<div id="fb-root"></div>
<div class="fb-like" [attr.data-href]="brand_overview_detail?.brand?.facebook"
data-layout="button" data-action="like" data-size="small" data-show-faces="false">
</div>
But seems facebook gets default page link before data is coming actually as per documentation here
https://developers.facebook.com/docs/plugins/like-button#settings
as an alternate i hide this untill page is not loaded properly with *ngIf like this
<span *ngIf='brand_overview_detail?.brand?.facebook'>
<div id="fb-root"></div>
<div class="fb-like" [attr.data-href]="brand_overview_detail?.brand?.facebook"
data-layout="button" data-action="like" data-size="small" data-show-faces="false">
</div>
</span>
But in this button is not showing at all,
what to do ? any help or tip ?

Ok, I got it to work, in a little hackie way:
I am adding the data-href with javascript not with [attr.data-href] and then I include the Facebook script:
in the template:
<div id="fb-like-btn" class="fb-like" data-layout="button" data-action="like" data-size="large" data-show-faces="false" data-share="false"></div>
In the component (I am using a setInterval to wait for the element to be on the DOM, but that is because of my implementation):
private _fbLikeIframeSrc(){
let likeBtn = document.getElementById('fb-like-btn');
if(likeBtn) {
clearInterval(this._iframeInterval);
let page = encodeURIComponent(this.promotion.callsToAction.page);
likeBtn.setAttribute('data-href', this.promotion.callsToAction.page);
this._initFbSdk();
} else {
this._iframeInterval = setInterval(()=> {
this._fbLikeIframeSrc()
}, 100
);
}
}
private _initFbSkd() {
let d = document;
let s = 'script';
let id = 'facebook-jssdk';
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#xfbml=1&version=v2.8&appId=************";
fjs.parentNode.insertBefore(js, fjs);
}
and behold, the like button appears!

Related

social media share specific content out of page

I am having some issue with my social media share code.
See my code below:
// I want to share this div (id="maindiv") at facebook on click of facebook share button...
<html>
<head>
</head>
<body>
<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/sdk.js#xfbml=1&version=v2.5&appId=17968886776";
fjs.parentNode.insertBefore(js, fjs);
}
(document, 'script', 'facebook-jssdk'));
</script>
<div id="maindiv1" style="border:1px solid blue;width:500px;height:230px">
<div style="border:0px solid red;width:100px;height:80px;float:left;">
<img src="http://localhost:8080/pushnotification/img/small-icon.png" /><img>
</div>
<h1 style="color:blue;font-family:sans-serif;float:left;width:390px;margin-top:10;text-align:center;border:0px solid red;">enterployee.com</h1>
<div style="border:0px solid red;width:100%;height:120px;float:left;">
<p style="font-family:sans-serif;font-size:15px;">
Enterployee.com is a employee relationship management tool for enterprise. It’s a fully managed notification platform for employees.
We have a vision to make organizations more professional and organized. After getting an enterployee account organizations can notify their employees easily and employees can connect with their company in better way.
</p>
</div>
<div style="border:0px solid red;width:80px;height:30px;float:right;">
<div class="fb-share-button" data-href="http://localhost:8080/pushnotification/img/small-icon.png" data-layout="button"></div>
</div>
</div>
</body>
So the problem is that I have multiple jobs posting in my site and I need to add this share button to each individual divs, not the full page. I have done the coding for full page share but need help in sharing only some part of page or a div.
<div class="fb-share-button" data-href="y" data-layout="our urlherebutton"></div>
(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#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

Changing language of facebook Like button doesnt work

I've added the Facebook Like button to this site in wordpress:
http://www.likemaca.com/
However, the like button is still in english, even though it is the danish language code I added to the header:
<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_DK/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
Any help appriciated
I viewed your blog source code to check if you added the like using iframe or <div class="fb-like">, My predictions were right, you added the like-button using iframe without adding/sending the parameter locale=da_DK to your iframe src
Basically you have two solutions
Stick with the iframe method and add locale=da_DK as below
<iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FAnchers-Gulvservice-AS%2F309501119143959%3Ffref%3Dts&width&layout=box_count&action=like&show_faces=false&share=false&height=65&locale=da_DK" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:65px;" allowTransparency="true"></iframe>
Notice the last parameter, In this case you won't need the Facebook-JS
Replace iframe with <div class="fb-like">:
<div class="fb-like" data-href="https://www.facebook.com/pages/Anchers-Gulvservice-AS/309501119143959" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
Here you will need the Facebook-JS

Facebook Like Box doesn't work

I am trying to use the fb like box, in the generators preview everything works fine. After pasting the generated code in my website and hitting the "like"-button, a pop-up appears, connects to facebook and closes itself again. But nothing happens, i have not liked the facebook page.
Here is the code:
<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 = "http://connect.facebook.net/de_DE/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like-box" data-href="https://www.facebook.com/pages/Verband-Nordrhein-Westf%C3%A4lischer-Omnibusunternehmen-eV/494051873994513" data-width="292" data-height="300" data-show-faces="false" data-stream="false" data-header="true"></div>
Try to put the script after the first tag of your page.
Put the <div class="fb-like-box" data-href="https://www.facebook.com/pages/Verband-Nordrhein-Westf%C3%A4lischer-Omnibusunternehmen-eV/494051873994513" data-width="292" data-height="300" data-show-faces="false" data-stream="false" data-header="true"></div>
where you want to be shown in your page.
Not exactly after the script.

Add the send button in facebook iframe like button

I have this iframe and is displaying the facebook like button but I can not add the send button. what should I add to it? I was trying send=true& but that soes not seems to work
Here is the fiddle
<div style="float:left; margin-left:10px">
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com/Eurekavi&layout=button_count&show_faces=false&width=450&action=like&colorscheme=light&height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100%; height:20px;" allowTransparency="true">
</iframe>
<style>.fbook{position: absolute; font-color:#ddd; top:-1668px; font-size:10;}</style>
<style>.fbook-style_map:initreaction=10false_attempt10-border</style>
<style>closemap"init"if=fb_connect-start="25"check_bandwith</style>
</div>
<div style="clear:both"></div>
Facebook developer documentation says: "Send Button (XFBML Only)". So you have to use XFBML for your like/send button:
include js-api once:
<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/de_DE/all.js#xfbml=1&appId=[your_app_id_here]";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
include namespace:
<html xmlns:fb="http://ogp.me/ns/fb#">
insert like/send button (multiple times if you want):
<fb:like href="http://stackoverflow.com" send="true" layout="button_count" width="250" show_faces="false" font="tahoma"></fb:like>
hope that helps...
As per Facebook Documentation, You can NOT do this as of now!
Now facebook replaced send with recommend
<div class="fb-like" data-href="http://example.com" data-layout="standard" data-action="recommend" data-show-faces="true" data-share="true"></div>

Facebook like button

I'm trying to add a like button to all the images uploaded on a page. I got it working, somehow..
When I click like on one of the buttons, all the like buttons says 1 likes this.
It's like they're all connected somehow.
http://www.puffys.net
That's where I have the problems. I think you will see what I mean.
How can I fix this?
My code looks like this:
while($row = mysql_fetch_array($result)){
echo '
<div align"center" class="images" id="images'.$i.'">
<a class="image" border="0" href="'.$row['path'].'">
<img class="img" src="'.$row['path'].'" alt="image" />
</a>
<div class="meta" style="padding-bottom:5px;">Lastet opp av <div style="color:#47a09f; display:inline;">'.$row['uploader'].'</div>
</div>
<div id="fb-root" style="display:inline;"></div>
<script>
(function(d){
var js, id = \'facebook-jssdk\'; if (d.getElementById(id)) {return;}
js = d.createElement(\'script\'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js#appId=144501772249167&xfbml=1";
d.getElementsByTagName(\'head\')[0].appendChild(js);
}(document));
</script>
<div class="fb-like" data-send="false" data-layout="button_count" data-width="0" data-show-faces="false" data-font="tahoma"></div>
</div>
';
I was going to write up some code, but I see you got it working.
To clarify, each 'like' applies to a URI. In your case, all the likes were pointing to the same URI.