i have the following js code but it does not work, i've tryed too much but no success:
•i already have a non expire full access token
•i have all permisions
<html>
<head>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<title>Invite</title>
</head>
<body>
<A href="#" onMouseOver="return changeImage()" ><img
name="jsbutton" src="http://cdn.property118.com/wp-content/uploads/2014/06 /Invite- friends-to-read-Property118-.jpeg" width="110" height="28" border="0"
alt="javascript button"></A>
<SCRIPT language="JavaScript">
window.fbAsyncInit = function() {
FB.init({ appId: xxxxxxxx,
status: true,
cookie: true,
xfbml: true,
oauth: true
version : 'v2.1'
});
};
(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'));
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
function renderMFS() {
// First get the list of friends for this user with the Graph API
FB.api('/me/invitable_friends?limit=3000&access_token="I already have a non expire full user access token",
function(response) {
var container = document.getElementById('mfs');
var mfsForm = document.createElement('form');
mfsForm.id = 'mfsForm';
// Iterate through the array of friends object and create a checkbox for each one.
for(var i = 0; i < Math.min(response.data.length, 10); i++) {
var friendItem = document.createElement('div');
friendItem.id = 'friend_' + response.data[i].id;
friendItem.innerHTML = '<input type="checkbox" name="friends" value="'
+ response.data[i].id
+ '" />' + response.data[i].name;
mfsForm.appendChild(friendItem);
}
container.appendChild(mfsForm);
// Create a button to send the Request(s)
var sendButton = document.createElement('input');
sendButton.type = 'button';
sendButton.value = 'Send Request';
sendButton.onclick = sendRequest;
mfsForm.appendChild(sendButton);
});
}
}
});
</SCRIPT>
<div id="fb-root"></div>
</body>
</html>
i want my code show something like this Example but when I click the botton nothing happens. thanks in advance
First of all, there is no non expiring User Access Token, an Extended User Token is valid for 60 days. But in any case, you don´t need to worry about Access Tokens while using the JavaScript SDK, because it takes care of the User Token for you.
That being said, there are a LOT of problems in that code:
The biggest problem is that you don´t have any authorization routine. Use FB.login to authorize users. And again, don´t worry about Access Tokens.
You are trying to use the synchronous AND the asynchronous way to include the JavaScript SDK. Always use the asynchronous way and forget about the synchronous way.
You are using FB.getLoginStatus and FB.api before initializing the JS SDK with FB.init. The whole block of code with FB.getLoginStatus should be either right after FB.init or in a function that is called on user interaction (mouse click).
That link does not do anything. There is no changeImage function anywhere in your code.
There is also no sendRequest function anywhere, and you are trying to call that function with that input button.
Just open your browser console and you may see some errors pointing some of those things out.
Btw, here´s an article about how to use the JS SDK in a proper way: http://www.devils-heaven.com/facebook-javascript-sdk-login/
Related
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.
I have a photo album I want to display on a website to anybody who visits. At the moment I'm using FQL to show the album but it only shows to me when I'm logged in to my account. Is there a way anybody knows of to authenticate a public user or even somebody without a facebook account to view the album?
Current code:
var fbAppId = 'xxxxxxxxx';
window.fbAsyncInit = function() {
FB.init({
appId : fbAppId, // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse page for xfbml or html5 social plugins like login button below
});
};
(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'));
function getPhoto() {
FB.api(
{
method: 'fql.query',
query: 'SELECT src_big, src FROM photo WHERE album_object_id = "[my album id]"'
},
function(response) {
if (!response || response.error) {
console.log(response.error);
} else {
console.log(response);
for (var i = 0; i < response.length; i++) {
$('#result').append('<img src=' + response[i].src + ' alt="" /> ');
}
}
}
);
};
If you are okay using a third party facebook widget, a simple solution without any programming knowledge to displaying facebook photos on a website to users who aren't logged in by using
<iframe src="http://facebookgalleria.com/gallery.php?id=nike&rows=4&margin=10&cols=3&width=170&font_size=11&title_color=000&hide_next_back=0&share_buttons=1&shape=rectangle&frame=1" scrolling="no" marginheight="0" frameborder="0" width="551" style="height: 769px;"></iframe>
Change 'nike' in the url to your facebook page username, copy the code and paste it on your html website editor and it'll display neatly. Or customize your gallery at http://facebookgalleria.com. However, if you display photos from your personal facebook account, you need to go to the website and connect with facebook first. Then you generate your code that will work on your website without your customers having to log in to see them.
Hope this helps.
If you view this question thank you in advance!, I am working on pulling data from Facebook.
I am trying to pull the username from Facebook so i can use it in a later stage I have embedded the following code in the FB Root div.
I know the retrieve works! however i am not able to pass it on to the function returndata I am relative new to javascript could you please help me out? i have tried everything
There is an alert in there to check if it is retrieving data
<div id="fb-root"></div>
<script type="text/javascript">
$(document).ready(function()
{
var appId = "121070974711874";
// If logging in as a Facebook canvas application use this URL.
var redirectUrl = "http://apps.facebook.com/bggressive";
// If logging in as a website do this. Be sure to add the host to your application's App Domain list.
var redirectUrl = window.location.href;
// If the user did not grant the app authorization go ahead and tell them that. Stop code execution.
if (0 <= window.location.href.indexOf ("error_reason"))
{
$(document.body).append ("<p>Authorization denied!</p>");
return;
}
// When the Facebook SDK script has finished loading init the
// SDK and then get the login status of the user. The status is
// reported in the handler.
window.fbAsyncInit = function()
{
FB.init({
appId : appId,
status : true,
cookie : true,
oauth : true
});
FB.getLoginStatus (onCheckLoginStatus);
};
(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";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
function onCheckLoginStatus (response)
{
if (response.status != "connected")
{
top.location.href = "https://www.facebook.com/dialog/oauth?client_id=" + appId + "&redirect_uri=" + encodeURIComponent (redirectUrl) + "&scope=user_photos,friends_photos";
}
else
{
FB.api('/me', function(response)
{
PASON = response.username
alert(response.username)
});
}
}
});
function returndata()
{
get = PASON
return get
};
</script>
I think you are calling the function returndata() at any random point which you can't do. The reason is- the variable PASON is assigned value asynchronously. So, you have to code in such a way that you call returndata() after the value is assigned!
Its not quite clear what you are trying to do with the function returndata(). But, I hope your concept is clear now.
For the life of me I cant get Event.subscribe('auth.authResponseChange') to work. See code below
<div id="fb-root">
</div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: 'XXXXXXXXXXXXXXX', // App ID
channelUrl: 'http://XXXXXXXX.us/', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function (response) {
alert('The status of the session is: ' + response.status);
});
};
// 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>
<div class="fb-login-button" data-size="xlarge" scope="email" data-show-faces="false"
data-width="400" data-max-rows="1" autologoutlink="true">
Login with Facebook</div>
The login button renders. and i can logout too. only problem is that the auth.response change is not firing and i am not getting the "message" popup
Your code looks fine.
I would access your Facebook app and check on 2 settings in particular.
Check 'Sandbox Mode' -ensure it's set to 'Disabled'
Check your Site URL and/or Canvas URL -ensure they are set to your domain. (i.e. if you are working on this locally your url should look something like http://localhost:#####/ where ##### is your port.
Hope that helps.
Your fbAsyncInit function is called asynchronously so you won't see any alert messages. Try console.log instead for debugging.
Couldn't find similar enough question so I'll ask.
I'm trying to use facebook log-in on my page.
I did everything according the the developer's guides.
However, I'm not sure when I can start calling FB.API calls. when is the user authenticated? how can I know when this operation was done?
<script>
window.fbAsyncInit = function () {
FB.init({
appId: 'someID', // App ID
channelUrl: '//www.domain.com/channel.html', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
};
// Load the SDK Asynchronously
(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";
d.getElementsByTagName('head')[0].appendChild(js);
} (document));
</script>
now I want to call this
FB.api('/me', function (response) {
facebookUser = response;
alert('Your name is ' + response.name);
});
but not sure when is the write time. I get undefined wherever I put it :/
You will want to run the FB.getLoginStatus() (https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/) before you send the user to log in using FB.login() or if the user is logged in, to call the FB.api() method.