I am using the facebook javascript sdk and graph api.my code is workin fine with single image.how to pass multi value parameter to image.
$("#ac").click(function()
{
FB.init({
appId : 'validappid',
status : true, // check login status
cookie : true,
xfbml : true // parse XFBML
});
FB.login(function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
console.log('Access Token = '+ access_token);
FB.api('me/posimplicity:eat',
'post',
{
restaurant: "http://samples.ogp.me/440002909390231",
image:'http://abc.in/images/items/120px-Chana_masala.jpg',
},
function(response) {console.log(response);
// handle the response
}
);
}
},{scope: 'read_stream,publish_stream,offline_access,user_photos'});
})
(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));
http://jsfiddle.net/BJK2b/33/
I want to show the all dishes images that ordered
Related
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '261852174300349',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
};
(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));
//LOGIN FUNCTION
function login() {
FB.getLoginStatus(function(response) {
console.log(response)
});
}
</script>
<div onclick="login();">Login with Facebook</div>
As per facebook document to check user is already login or not we can use FB.getLoginStatus get the user is log in or not but in my cause i can"t able to get any response
try this instead. It will call the login function right after being initialized. In your current code
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '261852174300349',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
//LOGIN FUNCTION
function login() {
FB.getLoginStatus(function(response) {
console.log(response)
});
}
};
(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>
<div onclick="login();">Login with Facebook</div>
I have this code:
<div class="fb-like" data-href="snip" data-layout="button"
data-action="like" data-show-faces="false" data-share="false"></div>
And this JavaScript:
$(document).ready(function()
{
var page_like_or_unlike_callback = function(url, html_element) {
console.log("page_like_or_unlike_callback");
console.log(url);
console.log(html_element);
}
function detectFBLike()
{
FB.Event.subscribe('edge.create', page_like_or_unlike_callback);
}
detectFBLike();
});
And I have a JavaScript include which initializes the FB JS SDK like so:
window.fbAsyncInit = function () {
FB.init({
appId : 'snip',
cookie : false,
xfbml : true,
status : false,
version : 'v2.1'
});
};
(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));
This generates an error: FB is not defined and the cause is this line
FB.Event.subscribe(
However in the console if I type FB it is recognized.
What am I missing?
i am having problem with publish dialog via javascript SDK. It sometimes work, sometimes dont.
It throws this error:
API Error Code: 102 API Error Description: Session key invalid or no
longer valid Error Message: Iframe dialogs must be called with a session key
My code:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'CENSORED', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// wait a moment before showing dialog.
setTimeout("showbox()", 2 * 1000);
};
// 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>
and
<script>
function showbox()
{
FB.ui(
{
display: 'iframe',
method: 'feed',
name: 'ASD ASD ASD:',
link: 'https://apps.facebook.com/XXX/',
picture: 'https://skvelazabava.eu/XXX/yy.jpg',
caption: 'Největší alkoholici mezi tvými přáteli jsou:',
description: ' ',
properties: [{text:"XXX", href:"https://apps.facebook.com/XXX/"},
{text:"YYY", href:"https://apps.facebook.com/XXX/"} ],
redirect_uri: 'https://url.eu/'
});
}
</script>
What do i have to do to make sure dialog will have session key.
This was also the case for me, to clarify for anyone else who encounters this:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{{facebook_app_id}}',
app_token : '<%=#access_token%>',
status : true,
});
FB.getLoginStatus(function(response) {
console.log(response);
FB.ui({
method: 'apprequests',
message: 'Have you heard about Rell?',
data: 'invite-to-rell-42',
display: 'iframe',
filters: [{name: 'Daaku', user_ids: ['1677846385']}, 'app_non_users', {name: 'Games People', user_ids: [703, 6203644]}]
});
});
};
// 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>
According to Facebook: "The best place to put this code is right after the opening tag"
Example:
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelURL : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// 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>
But I would like like to add this in the jquery block $(document).ready(function() { }
How can that be done?
Include jQuery, and then...
$(document).ready(function(){
callFB();
loginClick(); // Call function
});
function callFB(){
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelURL : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// 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));
}
function loginClick(){
// your click handling code in here
}
This is more what you're looking for I think...
https://developers.facebook.com/docs/javascript/howto/jquery/
You can try this jQuery plugin i made too.. :]
jQuery.fbInit = function(app_id) {
window.fbAsyncInit = function() {
FB.init({
appId : app_id, // App ID
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));
$('<div />').attr('id','fb-root').appendTo('body');
};
$(document).ready(function(){
$.fbInit('12345678901234');
});
On http://www.stubwire.com/account/login.php I am trying to add the Facebook Connect, and once they login it reloads the page. I have tried searching and I see other posts, but unable to figure out why my page is not working. Can someone help me figure out why this is not working?
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '139440482805508',
status : true,
cookie : true,
xfbml : true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.statusChange', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
window.location.reload();
});
};
(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>