JS - Post current quote to facebook - javascript

Here is what I'm aiming for -
When a user clicks 'Facebook' button - I'd like the text highlighted in green here:
URL - cl.ly/TlH6 - to post to their profile.
Here is the site - http://afrifacti.com
Here is what I have so far:
1 - Signed into my main facebook account - but it doesn't have the quote - the URL=>cl.ly/Tkjj
2 - Signed into my tester facebook account - it doesn't post anything - the URL=> cl.ly/TkhL
Any thoughts on why it would work with one and not the other?
Any help would be appreciated here is the code:
<script src="assets/js/lib/jquery.js"></script>
<script src="assets/js/lib/underscore.js"></script>
<script src="assets/js/quotes.js"></script>
<script src="http://platform.twitter.com/widgets.js"></script>
<div id="fb-root"></div>
<script type="text/javascript">
// facebook setup
window.fbAsyncInit = function() {
FB.init({ appId: '665401243510103', status: true, cookie: true, xfbml: true });
FB.getLoginStatus();
};
(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'));
var quote = null;
(function showRandomQuote() {
var randomQuoteIndex = Math.floor(Math.random() * quotes.length);
quote = quotes[randomQuoteIndex];
$("#raw-quote").text(quote.rawQuote);
$("#date").text(quote.date);
$("#author").text(quote.citation);
$("#date").text(quote.date);
$("#link")
.attr("href", quote.link)
.attr("title", quote.altText)
.text(quote.linkText);
})();
(function setupFacebookButton () {
$("#facebook-button").click(function() {
FB.ui({
method: 'feed',
name: quote.date + " quote of the day",
link: 'http://www.afrifacti.com/',
caption: quote.altText,
description: "the description",
message: quote.rawQuote
});
});
})();
</script>
-
Ry

I visited the site and saw "an error occured" when I clicked the FB button. A common reason for this to fail is that your app is in Sandbox mode, which means only developers on the project can access it.
As for the quote not showing up, try putting a "testing testing 123" type string in for message to see if that shows up in your feed box. If not then there may be a problem with quotes being defined inside showRandomQuote()

Related

How to check User facebook page like or not in v3.1

I have crated app on this link https://developers.facebook.com/ My app version is v3.1. I have use facebook api only scripting.
I want to check current user is like facebook page or not,If user is not like facebook page then request to like page,if user is liked then content are showing.
window.fbAsyncInit = function () {
FB.init({
appId:'xxx',
xfbml: true,
cookie: true,
status: true,
secret: 'xxx',
version: 'v3.1'
});
FB.Event.subscribe('edge.create',
function (href, widget) {
//alert('Ti piace ' + href);
//document.getElementById('fb-like').style.display = "none";
//var x = document.getElementsByTagName("button")[0].getAttribute("title");
// alert(x);
});
FB.api({ method: 'pages.isFan', page_id:'xxx' }, function (resp) {
console.log(resp);
if (resp) {
alert('You like it.');
} else {
alert("You don't like it.");
}
});
};
(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'));
Error are occurred like this. I am tired please help me this problems.
erro_code:"104" erro_msg:"Incorrect signature(104),request_args:Arrar(7),error_subcode: "0"
Gating content behind likes is not allowed since many years.
The edge.create event has been removed. It would only allow to detect new likes anyway, not existing ones.
"pages.isFan" is very old, it would be /me/likes instead to get the Pages a user likes. And that only works if the user authorizes your App with the user_likes permission. You will not get that permission approved in the review process for like gating or incentivizing users to like your Page in any way.
TL;DR: Not possible and not allowed.

Facebook JavaScript SDK from browser console

I am trying to create a script for Facebook Messenger which is intended to be run from the browser console. As part of the script's functionality, I need to access the Facebook Graph - here is the relevant code:
window.fbAsyncInit = function() {
FB.init({
appId : '(my app's ID is here)',
autoLogAppEvents : true,
xfbml : true,
version : 'v2.12'
});
FB.api(
'/me?fields=name',
'GET',
{fields: 'name'},
function(response) {
if (response && !response.error) {
console.log(response);
}
else {
console.log("Error with SDK!");
}
}
);
(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_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
};
Most of the code is copied from the Facebook help page. Unfortunately, when run, neither the request response nor the string 'Error with SDK!' are logged to the console.
I am not quite sure why this doesn't work as intended and one of my thoughts is that the code has to be executed from an actual web page - however, this is not an option since the code has to be run directly from Messenger in order to obtain its source code. This can not be done from another URL due to the Same-Origin Policy. Any help is greatly appreciated!

FB web share dialog not giving option to send as message

I am using Facebook's SDK with Require JS and Backbone JS. I have a share button that triggers a fb share display. It shows up as expected, but does not give the option to share as a message. All other options (timeline,group,event,page) appear. Is there a reason why?
my facebook sdk load module (copied/generated from fb developer guide):
define(["facebook"], function(FB){
FB.init({
appId : '', // my id is here
xfbml : true,
version : 'v2.9'
});
FB.AppEvents.logPageView();
(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 how I use it in a backbone view:
clickFbShareHandler: function() {
var dialogue = "I got " + this.model.getValue()";
FB.ui({
method: 'share',
mobile_iframe: true,
href: '(my url)',
quote: dialogue,
}, function(response){});
}
here is an image of the options given to me:
You can use the Send Dialog for that: https://developers.facebook.com/docs/sharing/reference/send-dialog
Alternatively, you can use sharer.php, that´s what you saw on other pages. It just needs the url as parameter: https://www.facebook.com/sharer.php?u=[xxx]

How to use facebook login in parse.com backend on website?

I am trying to integrate parse database with my website. It is almost one day I spent but I couldn't figure out the problem. Here is my code:
<div id="fb-root"></div>
<script>
Parse.initialize("**************************", "**********************");
window.fbAsyncInit = function() {
Parse.FacebookUtils.init({
appId : '*****************',
cookie : true,
xfbml : true
});
Parse.FacebookUtils.logIn(null, {
success: function(user) {
if (!user.existed()) {
alert("User signed up and logged in through Facebook!");
} else {
alert("User logged in through Facebook!");
}
},
error: function(user, error) {
alert("User cancelled the Facebook login or did not fully authorize.");
}
});
};
(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.3&appId=920929871279093";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-login-button" data-max-rows="3" data-size="medium" data-show-faces="true" data-auto-logout-link="true"></div>
My problem is that when I run this piece of code I get following error but login button appears and work fine.
As I search for this issue people are saying I change
//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3&appId=920929871279093";
To
//connect.facebook.net/en_US/sdk.js#xfbml;
or
//connect.facebook.net/en_US/sdk.all;
I do not understand how this really work. And appreciate if anyone say where I am calling init.FB twice and how to fix it.
I think you need to put version number in init function:
The following is the example from parse.com https://www.parse.com/docs/js/guide#users-setup
<script>
// Initialize Parse
Parse.initialize("$PARSE_APPLICATION_ID", "$PARSE_JAVASCRIPT_KEY");
window.fbAsyncInit = function() {
Parse.FacebookUtils.init({ // this line replaces FB.init({
appId : '{facebook-app-id}', // Facebook App ID
status : true, // check Facebook Login status
cookie : true, // enable cookies to allow Parse to access the session
xfbml : true, // initialize Facebook social plugins on the page
version : 'v2.3' // point to the latest Facebook Graph API version
});
// Run code after the Facebook SDK is loaded.
};
(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>

How to only display content to visitors that have 'Liked' my website

To explain, I'd like for a link to only become available for clicking once visitors have 'Liked' my website (not my Facebook page - the actual website). I've been trying to do it using this code:
<script>
FB.Event.subscribe('edge.create', //FB.event.subscribe attaches a handler to an event and invokes your callback when the event fires.
function(response) { //This is where the response function is inserted, I used document.write for this example
document.write(';This is the HTML I want to display');
}
);
</script>
But even after I like my website the link doesn't display. I hope I've been as clear as possible, any help would be greatly appreciated.
I managed to get it working after some thinking and playing around:
<!-- FB Javascript SDK -->
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: 'APP-ID',
channelUrl : '//WWW.WBESITE.COM/channel.html', // Channel File
status: true,
cookie: true,
xfbml: true,
oauth: true,
});
// Additional initialization code here
FB.Event.subscribe('edge.create', function() {
window.location.href = "http://WEBSITE.COM/";
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<!-- More FB Javascript SDK (Like 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/en_US/all.js#xfbml=1&appId=APP-ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<script src="//connect.facebook.net/en_US/all.js#xfbml=1">
</script>
The FB.Event.subscribe needed to be placed within the window.fbAsyncInit function. I then made it so that instead of having the HTML appear after the 'Like' button had been pressed it simply redirected it using the window.location.href = "http://WEBSITE.COM/"; to a page that has the new link included on it. The document.write function wasn't working because it would get rid of all the HTML on the page other than what was included in the function.
The code above needs to be placed just after the opening tag and then you can place the code for the 'Like' button:
<div class="fb-like" data-href="http://WEBSITE.COM" data-send="send" data-layout="button_count" data-width="450" data-show-faces="true"></div>
Anywhere that you would like on the page!

Categories

Resources