Inserting facebook share button on personal website - facebook

I want to put a button on my website that will open a popup for the user to share the url on its profile.
I followed the steps shown here, after click on 'get code':
1. Include the Javascript SDK on your page once, ideally right after the opening <body> tag.
2. Place the code for your plugin wherever you want the plugin to appear on your page.
but I get a blank div without the button. What's missing? Do I need to register on facebook developers? Do I need to include some javascript src in the <head>?
On twitter is very simple, you just need to get the code from here
Edit: I want something like youtube facebook share.

As noted in the comments, somehow the default method as suggested by Facebook is not working, or rather the way the share button documentation suggests is not clear enough. This answer as suggested appears to work. Note that you will need a Facebook App ID.
Alternatively, this answer allows for a simple link, which you then have to style yourself with CSS, this alternative has the benefit of making share buttons that are consistent in design with your website, if you just want the vanilla blue Facebook button then continue with this answer.
Squarespace also details the default way of adding a facebook like button, my attempts to get it to work in a jsFiddle were not successful.
Get an AppID and embed the Facebook script in your website.
This step is explained in detail in the official documentation, where you just generate your own AppID then copy paste the script code (usually after the <body> tag.
Add a jQuery library for the next bit of code as explained in this answer.
The share dialog box script:
-
<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: 'This is the content of the "name" field.',
link: 'Your-blog-link',
picture: ‘http://yourpicture-here’,
caption: 'yourCaption',
description: short-description-here
message: ''
});
});
});
</script>
More parameters can also be added to customize the button.
Lastly, add the image/element you want to be the share-button:
Something like: <img src = "share_button.png" id = "share_button">

Related

AddThis and History.js - automatic redirection to wrong URL

I have a problem with AddThis widget and History.js script.
Once user shares some page on Facebook using AddThis widget, some hashtag is appended to URL (e.g. #.U-S_Q-q0tE8.facebook).
Then, if user clicks such link on Facebook and goes to my website with URL e.g.: http://domain.com/path/to/content,123.html#.U-S_Q-q0tE8.facebook, they get redirected to http://domain.com/path/to/.U-S_Q-q0tE8.facebook which throws error 404.
The weird thing is that History.js is not even initialized or used. It's just embed on the site with <script...> tag.
Is there any solution to this? Is it possible to disable such behavior in History.js?
I have the exact same problem, and while I don't know if you can disable the history.js behavior, you can disable the addthis hashes by adding the following before the addthis script
<script type="text/javascript">
var addthis_config = {
data_track_clickback: false
}
</script>
This means you wont be able to track how many click that link gets using addthis, but something like Google Analytics is able to show traffic source.
Source

modX add og:image and og:description dynamically

I am trying to create a Facebook share option for my blog articles, and it works but it doesn't take the article text or image, but the first image and text on the (single page) website. How can I change my share code so that it will use the article's image and text from where I click the FB share button?
This is the template for the blog article, with the FB share code included:
<div class="contentLeft">
<div class="roundimage">
<a href="[[+roundImage:phpthumbof=`h=750&zc=1`]]" class="colorbox" title="[[+roundImageCaption]]"><img class="round"
src="[[+roundImage:phpthumbof=`w=170&h=170&zc=1&q=95`]]" alt="[[+roundImageCaption]]" /></a>
</div>
<script type="text/javascript">function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script>
<h4 class="blue" style="margin-bottom:10px; margin-top:0;">[[+articleHeadline]]</h4>
<p class="datetext">[[+datetimeText]]</p>
<p class="readmoretext">[[+articleText]]</p>
<div class="divider"></div>
</div>
I hope you can help! Thank you!
It should be enough to make sure that the article page, ie the link that you are sharing, embeds the correct og:image and og:description. You only share the link with the share button, and facebook will embed the link and look in it for the proper data.
Update:
I guess you're not using the articles package to create the blog? If you are you already have individual pages even if you're not using them =) If you're not i assume you're using some sort of resource loop to create your entries.
After looking around in the facebook docs it seems you can specify the image (https://developers.facebook.com/docs/opengraph/using-actions/v2.0#params) when creating your share button using the javascript sdk (https://developers.facebook.com/docs/sharing/reference/share-dialog). Each article will need to call something like this instead of the current javascript share url functionality.
FB.ui({
method: 'share_open_graph',
action_type: 'og.likes',
action_properties: JSON.stringify({
image: "YourImageForThisRespectiveShare",
})
}, function(response){});
If you prefer to explore the method i mentioned in the comments it would go something like this:
Look in your code at u=location.href;, you'd want to try modifying that to u=location.href+'?articleid=[~[*id*]~]';. When you share you should hopefully see the appended article ID for each article.
You'll then need to make sure you can specify og:image and description for each article, i assume you somehow have resources set up that represent each article, in that case just create a couple of template variables for that resource type.
In your header you could then use the getResourceField package for example to retrieve the correct TV from the correct resource, as specified by the ?articleid= parameter in your URL.
To retrieve the parameter you'll need a simple snippet like return (!empty($_GET['articleid']) ? $_GET['articleid'] : $default);. Lets name the snippet: "getArticleId". I left the option to decide a default image when there is no &articleid specified.
You're using modx evolution from the look of your [~[*id*]~] tag, but there should be some equivalent of the getResourceField package for evolution. This is the revolution version of the code needed:
<meta property="og:image" content="[[!getResourceField?
&id=`[[!getArticleId? &default=`[[*id]]`]]` //Take the blog page's own image as a default
&field=`imageTV` //you'll of course have to change "imageTV" to whatever you call it
&isTV=`1`
]]" />
Repeat for og:title and og:description, with their respective TV names.

og meta tags, social buttons and angularjs

I'm creating a website using multiple views.
The tag and the tags of the page get changed through a a $rootScope variable.
so I have something like
<html>
<head>
<title ng-bind="page_title"></title>
<meta property="og:title" content="{{page_title}}">
</head>
Whenever each view get loaded on the website, the page_title variable changes and the title and the og:title tags get updated (everything works as expected).
The problem is that I need, on some views to load a facebook, a google+ and a twitter button.
I can display them properly but if I click on each them the page title appear to be something like:
{{page_title}}
I've tried to delay the execution of the scripts of each button using setTimeOut but to no good.
But the scripts just read whatever is written, they don't parse the page_title.
Does anyone know a workaround to this?
Thank you
This can't be done using javascript. Some people think that Facebook is reading what's currently on the page. It's not. It makes a separate request to your server using the same url (from window.location.href) using it's Scraper, and the Facebook Scraper does not run javascript. That's why you get {{page_title}} when clicking on something like a Facebook share button. Your content will have to be generated by the server so when Facebook goes to hit the url it gets the content it needs up front without the need for javascript. You can tackle the server side rendering in a fews ways.
You can allow your server side technology to render the content.
You can use the PhantomJS approach https://github.com/steeve/angular-seo.
There's also a possibility that you can re-render Facebook widgets. Use their parse method:
FB.XFBML.parse();
after your angular stuff has completed. It's not working for my share button (yet!!), but I tested it on likes, and it's cool. Basically it re-scans the DOM and renders the Facebook widgets. You can also pass it a single element, something like this directive:
'use strict';
angular.module('ngApp')
.directive("fbLike", function($rootScope) {
return function (scope, iElement, iAttrs) {
if (FB && scope.$last) {
FB.XFBML.parse(iElement[0]);
}
};
});
This snippet would rescan the DOM for html5 facebook fb-like widgets when creating the last element in angular repeater.

Facebook feed link back to article not working for Facebook Comments implemented on custom CMS

I implemented facebook comments across a legacy, custom CMS. I used the XFBML implementation. Everything works as expected except when clicking the links back to the article page from a commenter's facebook feed the comment box does not show any comments. The link is of this form:
{Article URL}?fb_comment_id={comment_id_string}
And if I remove the comment parameter and only go to the article url the comment box renders correctly with the comment and all other comments on the article. So, it's some issue with the fb_comment_id parameter. One weird thing about how I had to implement the comments is, because of how the routing on the site works, I could not use server side code to set the the URL parameter in the <fb:comments> object. So I had to use this jquery code in the <head>:
<script>
// assign current page to comments url
$(document).ready(function() {
$('fb\\:comments').each(function(){
$(this).attr('href', window.location);
});
});
</script>
And used this for the actual <fb:comments> code:
<fb:comments href="{site's root URL}" num_posts="8" width="570"></fb:comments>
So, I figure doing this client side may be causing the issue. Not doing this server side is a hard constraint though, and everything else works so I'm hopeful there may be some way to make this work. If making the comment link work correctly is impossible, a reasonable hack would be to rewrite the link in the facebook feed so that it just points to the article url without adding the comment parameter. Any suggestions? Thanks!
NOTE: I've also tried using the html5 comments implementation and there is the same issue.;
Once facebook has rendered the iframe based upon your fb:comments tag, does it have the correct url? I am thinking it does not. You may have to call FB.XFBML.parse() after you inject the complete

No menu for 'Add to my Page' after creating canvas?

If I create a canvas and open the app profile page, It is showing a new look taking the left side area and there is no menu for 'Add to my Page'. What am I doing wrong? I am just unable to include a tab to a page.
I am trying to create an app to run my iframe, I used the following settings.
Apps On Facebook:
Canvas URL - Enter (http://YOURAPPLICATIONID.iframehost.com/)
Secure Canvas URL: (https://YOURAPPLICATIONID.iframehost.com/)
Page Tab:
Tab URL - Enter http://(YOURAPPLICATIONID.iframehost.com/tab)
Secure Tab URL- Enter (https://YOURAPPLICATIONID.iframehost.com/tab)
However there docent appear to be a way to "Add to my page" from the app profile page. I am following this tutorial.
http://www.youtube.com/watch?v=uoLpR2u7Ul8
Use the following to add to your facebook page:
http://www.facebook.com/add.php?api_key=[APP-ID]&pages=1
Replace [APP-ID] with your app id
Hope it helps.
Facebook are continuously changing things so most of the non-FB documentation and tutorials get outdated very quickly (which is a pain because they are much easier to understand than FBs own documentation!)
This time they're changing how the App Profile pages work, and some changed have been made since last week. You can find out the new way of adding your page here:
http://www.hyperarts.com/blog/facebook-removing-app-profile-pages-on-feb-1-2012/
Basically, you need to
Use the "Create Facebook Page" button in the edit app page
and either:
2 Create a link for others to add your tab using code similar this:
<a href="#" onclick=window.open("http://www.facebook.com/dialog/pagetab?app_id=176217385757369&next=http://tabpressapp.phpfogapp.com/content/pages/","PageTab","width=800,height=500");>Add TabPress to Your Fan Page!</a>
or 3. For your own private use code similar to this:
https://www.facebook.com/dialog/pagetab?app_id=176217385757369&next=http://tabpressapp.phpfogapp.com/content/pages/
(replacing with your own app_id & nexturl obviously!)
Edit: forgot to mention, the url for "next" is either the “Canvas URL” or “Page Tab URL” you used in your edit app page.
I haven't had to do this myself yet, but please let me know how it goes because I will soon!
https://www.facebook.com/dialog/pagetab?app_id=YOUR_APP_ID&next=YOUR_URL
Where YOUR_URL = the website address where you upload the HTML files.
Ref: https://developers.facebook.com/docs/appsonfacebook/pagetabs/