I want to have a "facebook share" link or button on a web page. The idea is to to share a link and a brief description, identical to twiter. No image or title of page is needed
In the past, the following link worked:-
"http://www.facebook.com/sharer.php?u=" + complete_url + message
Now, facebook ignores the message and it discards the complete url link. Instead it only displays the title of the homepage.
I found this answer on stack overflow:-
Make my own custom Facebook share button.
Having tried it (the script below) - I get the error: 'FB' is undefined
I'd be grateful if you could tell me:-
1. what am I doing wrong?
2. do we have to download the sdk.js from facebook server everytime?
The script is like this:
<html><head>
<script>
function onClick() {
FB.ui({
method: 'share',
href: 'the_complete_url_to_specific_page'
});
}
window.fbAsyncInit = function() {
FB.init({
appId : 'my_facebook_id',
xfbml : true,
version : 'v2.3'
});
};
(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>
</head>
<body>
<a href='#' onclick='onClick() ;return false;'> share on FacebookR</a>
</body>
</html>
First of all: No, you do not need to change the API version. Only if you need to use something that is only available in newer versions, check out the changelog once in a while: https://developers.facebook.com/docs/apps/changelog
You get the "FB is undefined" error if the JavaScript is not loaded (yet). Most likely you are not trying your code on a real server (it can also be localhost) but from your file system. You can try adding "https" to the source like this, or (better) test the code on a real server:
js.src = "https://connect.facebook.net/en_US/sdk.js";
The App ID is NOT your User ID, it´s an ID you get after creating an App here: https://developers.facebook.com/apps
Btw, the user can enter the message right when the Share Dialog pops up.
Related
I'm trying a simple Share dialogue, invoked via Javascript a website page. I can load the SDK fine:
window.fbAsyncInit = function() {
FB.init({
appId : '{My-App-ID}',
xfbml : true,
version : 'v2.0'
});
};
(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'));
And my javascript function is taken straight from the FB Docs:
FB.ui(
{
method: 'share',
href: 'https://developers.facebook.com/docs/'
}, function(response){});
The issue is testing. I've created a Test App within my main app for this purpose. My Personal Facebook account is an administrator for this App. When logged into my personal account I can invoke the share dialogue and it works fine.
However when I create a 'Test User' from the Roles -> Test Users section on the App Dashboard and log in as them, I get the following error when trying to invoke the share dialogue:
Sorry, this feature isn't available right now: An error occurred while
processing this request. Please try again later.
Very frustrating as I want to test using a test account. Any clues as to why this isn't working? Many thanks.
I've created a Facebook App and am using the FB developer tools to share content on a site.
However, when a link is shared it is titled "xxx shared a link via Widget Share Log App". I've seen other sites change this to read something like "xxx shared a link via Irrawaddynews" and I wondered if it was possible to do the same here.
BTW, I'm initiating the Facebook SDK with the code below (as per the instructions here: "shared a link via Widget Share Log App." - but this didn't solve my problem).
window.fbAsyncInit = function() {
FB.init({
appId : '{MY_APP_ID}',
status : true,
xfbml : true
});
};
(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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
In your App ID settings on Facebook, there are a few fields you have to update. We wrote pretty detailed setup instructions for doing this in conjunction with our own share software, but there's a general section beneath that for setting up the Facebook app:
https://naytev.zendesk.com/hc/en-us/articles/202777178-Link-Naytev-to-Your-Facebook-App
#userfuser - you actually don't need their validation, you simply need to make the app active. The process has a pretty terrible UX, and missing fields like "support email" will cause you to not be able to activate without a helpful error message.
I have added a facebook like button to my website. I am able to see a like button on the webiste. However when I click the like button, the like count increases but I receive a 401 authorisation required error in the pop up.
On reading facebook documentation further on facebook scrape url. I went to Object debugger and debugged the home page of my website.
When I clicked the link for scrape url I get this message
"document returned no data"
When I clicked the graph api link, I get this as the ouput.
{
"id": "id_nos",
"url": "http://sitename.com /",
"type": "website",
"updated_time": "2014-03-06T04:30:13+0000",
"created_time": "2014-03-04T06:58:54+0000",
"is_scraped": false
}
Can anyone tell me, how I am suppose to handle this error. What steps I will have to take to fix this issue?
Thanks in Advance
Updated the code for like button:
<div class="like-box">
<div class="fb-like"
data-href="<?php echo $poll['short_url']; ?>"
data-send="false"
data-layout="button_count"
data-width="20" data-show-faces="false">
</div></div>
The script is :
(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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Update 2:
The site is protected and asks for username and password (Http authentication). Could this be the reason?
Facebook needs to access your site in order to retrieve the Open Graph tags. If your site is protected with HTTP authentication Facebook cannot do so, and so like/share operations won't work correctly.
I'm using the module "facebook like box" in my homepage:
<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/it_IT/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
I put this code immediately after body tag and I put this in left side:
<div class="fb-like-box fb-box-laterale" href="http://www.facebook.com/RistorantiRomaRisto.it" data-href="http://www.facebook.com/platform" data-width="190" data-height="380" data-show-faces="true" data-stream="false" data-header="true"></div>
All works done, but I receive this error in console: FB.getLoginStatus() called before calling FB.init()
I've just read other conversation where i read that "You need to load the api asynchronously" and I followed their instructions with no result.
How can I solve it?
This happen because you don't add an appId to the url you set for facebook.
See the complete code Facebook generate here: https://developers.facebook.com/docs/reference/plugins/like/
As you'll see, the url is written like this: //connect.facebook.net/fr_CA/all.js#xfbml=1&appId=YOUR_APP_ID
The presence of this appId, will automatically call FB.init() with basic app settings. But as you removed it, FB isn't calling it's init function, and call .getLoginStatus() directly.
So, go create a app for your website, and add the app Id to the code snippet in order to remove this error.
Hope this help !
I'm really confused.
I'm trying to use some of the very simple Facebook plugins on my site, specifically the basic "Like" button.
I already know how to use the limited version with an iFrame.
However, now I'm trying to figure out the XFBML method and the online documentation seems to make a lot of assumptions about what you already know and really short on working examples. For example, they show you how to call the JavaScript Init and give you the single line of HTML code for element fb:like... but I could not see any examples of how to show/hide faces, set the default font, etc. like in the iFrame code.
I've since figured out that you need to add them as attributes to the element but that was thanks to StackOverlfow and no thanks to the Facebook documentation which simply takes you in circles.
<fb:like href="http://mydomain.com" show_faces="true" action="recommend" colorscheme="light" width="400" height="35" />
Ok, so now when using the XFBML code, it's height should expand/contract automatically depending on being logged in or not I assume.
I do not know if I'm supposed to initially set the height to "80" or if that happens automatically.
And I have no idea what I'm supposed to use for 'your app id' in the Init script. There is no App... just a Facebook Company Page... so why would I need an App Id when I'm just putting a Like button on a website?
<script>
window.fbAsyncInit = function() {
FB.init({
appId: 'your app id',
status: true,
cookie: true,
xfbml: true
});
};
Any enlightenment on these issues would be appreciated.
Thank-you!
Answering my own question, after pulling out all my hair...
http://developers.facebook.com/docs/guides/web/
"The JavaScript SDK requires that you register your website with Facebook to get an App ID (or appId). The appId is a unique identifier for your site that ensures that we have the right level of security in place between the user and your website. The following example shows how to load the JavaScript SDK once you have your appId:"
http://developers.facebook.com/setup/
The title of that page/form is Create an App. I still don't understand why they don't use more generic terminology. I'm not "creating an app" and I don't consider my website to be an app.
I don't have an appId but just got this code from the like code generator and it seems to work in my local environment (which uses localhost:8000 yet still has 136 likes). When I press the buttons I get the facebook login popup as expected.
<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>
<fb:like href="url here (optional)" send="true" width="450" show_faces="true"></fb:like>
you can do...
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#" >
...
window.fbAsyncInit = function() {
FB.init({
// appId : 'none', // App ID
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('edge.create', function(href, widget) {
var ss=href;
if (ss.match(/myWebSite/i)) {
alert('You just liked me');
}
});
};
(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 = "https://connect.facebook.net/en_GB/all.js#xfbml=1";
//js.src = "https://connect.facebook.net/en_GB/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
...
<fb:like ref="core" class="fb-like" data-href="http://www.mySite.com"
data-send="false" data-layout="button_count"
data-width="50" data-show-faces="false" data-colorscheme="dark"></fb:like>
the above works, but Like yourself, and and note how Facebook divides up real Likes with Facebook registered sites (giving a spash page, #followers, #talking, etc), from Liked urls it does not know. (the site does, at least, get a increasing counter). It kinda defeats the purpose of being Liked at all. I might be wrong, but I think it does not even post messages about the latter.
this is too bad, because I am running out of phone numbers for Facebook :)
Then, for me at least, there is a bigger problem. If you are going to reward someone for Liking you, you can't really be sure they did, because this is js. If you try to js redirect to a reward page, a user can just cut paste that url. You could set a rnd session var, pass it to js, and redirect js to a php page with it, but a user could figure that out too.
You cant seem to (or commented out appId) ...
require 'face_sdk/face/src/facebook.php';
$facebook = new Facebook(array(
'appId' => '',
'secret' => '',
));
$user = $facebook->getUser();
so there seems no direct php way. I was playing with passing the iframed Like button url to php, parsing it with simple_html_dom.php, and finding which of the two main divs has the class 'hidden_elem'. But in the end, it just isn't worth it because Facebook will treat you like a second class citizen.