In my application I want post a text message in facebook wall streemPublish but it is not working, can anyone tell me what i did wrong else guide me a good working tutorial,
also the below code does not showing any error....
Here is my code ...
<body>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript">
function publish() {
FB_RequireFeatures(["Connect"], function() {
FB.Facebook.init('113700398662301', 'xd_receiver.htm');
FB.ensureInit(function() {
var message = 'this is message';
var action_links = [{ 'text': 'Vote for Bill The Aircraft Carrier!', 'href': 'http://spayday.factor360.com/contest.html?page=viewInd&id=48082&contestId=2'}];
FB.Connect.streamPublish(message, action_links, null, "Share your support for Bill The Aircraft Carrier!", callback, false, null);
});
function callback(post_id, exception) {
alert('Wall Post Complete');
}
});
}
</script>
</body>
<p>Stream Publish Test</p>
Post a story
</html>
The code looks a little dated. Check this for updated info on stream publishing
https://developers.facebook.com/docs/reference/javascript/FB.ui/
and this for setting up your FB init.
https://developers.facebook.com/blog/post/525/
Related
Currently i am using the google cloudprint button for my site
<script src="//www.google.com/cloudprint/client/cpgadget.js"></script>
<script defer="defer">
var gadget = new cloudprint.Gadget();
gadget.setPrintButton(document.getElementById("custom_print_button"));
gadget.setPrintDocument("url", "Cloud Print test page",
"http://www.google.com/cloudprint/learn/");
</script>
I want to send an email when I hit the print button, is this possible?
No problem at all... just attach an onclick handler to the print button, or bind the click with jQuery and call a function to do your email. I used it to create a document with Ajax before it was printed:
<script>
function printIT() {
jQuery.ajax({
url: "print_this.php",
context: document.body,
success: function(responseText) {
alert("Document sent!");
return false;
}
});
}
</script>
<button id="print_button_container" class="ui-link" onclick="printIT();"></button>
<script src="//www.google.com/cloudprint/client/cpgadget.js">
</script>
<script defer="defer">
var gadget = new cloudprint.Gadget();
gadget.setPrintButton(document.getElementById("print_button_container"));
gadget.setPrintDocument("url", "My Document", "http://www.yourpath.com/yourdoc.html");
</script>
Simplified version... not tested but should work :)
I am using different facebook dialog boxes on my external website(a kind of facebook application) for tasks like posting to feed, Sending app requests etc. Earlier all dialogs were displaying properly but from last couple of days I have been experiencing display issues as dialog are not displaying to there full height.
I have tested on Chrome, Firefox and Safari browsers, at all places same issue.I even asked some of my friends to check at there places, as a result they are also facing the same.
Here is the snapshot link:
Here is the code to one apprequest dialog, I m using:
<body onLoad="warmup();">
<div id="fb-root"></div>
<script>
function sendRequest(type) {
var request = {
method: 'apprequests',
message: 'Hey! I Just Wanted You To Fill My Slambook.',
data: type,
title: 'Select friends'
};
FB.init({
appId:'xxxxxxxxx', cookie:true,
status:true, xfbml:true
});
FB.ui(request, function (response) {
if (response && response.request_ids) {
document.getElementById('sent').style.display='block';
} else {
}
})
}
function warmup(){
FB.init({
appId:'xxxxxxxxx', cookie:true,
status:true, xfbml:true
});
}
This is a bug that will be fixed soon: http://developers.facebook.com/bugs/194725433940802
A little trick that work for me:
var HACKAppRequests = {
id_interval:0,
busca:function(){
var i,fb_root,iframe;
try{
fb_root = document.getElementById('fb-root');
iframe = fb_root.getElementsByTagName('IFRAME');
recorre_iframe:
for(i=0;i<iframe.length;i++){
if(iframe[i].className=='FB_UI_Dialog'){
clearInterval(HACKAppRequests.id_interval);
iframe[i].style.height = '550px';
break recorre_iframe;
};
};
} catch(err){};
}
};
FACEBOOK CALL
function buscaAmigosFB(){
FB.ui({method:'apprequests',
title:'Esto es sólo para TI',
message:'He decidido comenzar a escribir una historia. ¿Te atreves a escribirla conmigo ;D?',
max_recipients:1
},someFunction);
// RESIZE
HACKAppRequests.id_interval = setInterval(HACKAppRequests.busca,250);
};
Im fancing a really weird problem with the edge.create callback.
What im doing is to execute an ajax call to the server each time an edge.create or edge.remove event occurs (the firs is to like and the second to unlike a page).
Heres the code
// this will fire when any of the like widgets are "liked" by the user
FB.Event.subscribe('edge.create', function(href, widget) {
var dataSend = 'ajaxFace=true&submitAdd=true&code='+SomeCodeToAdd;
$.ajax({
type: 'POST',
url: 'http://somewebpage.com',
data: dataSend,
success: function(data) {
alert(data);
},
erro: function(data) {
alert('Try again later');
}
});
});
//this will fire when any widgets are "disliked" by the user
FB.Event.subscribe('edge.remove', function(href, widget){
var dataSend = 'ajaxFace=true&submitDelete=true&code='+SomeCodeToRemove;
$.ajax({
type: 'POST',
url: 'http://somewebpage.com',
data: dataSend,
success: function(data) {
alert(data);
},
erro: function(data) {
alert('Try again later');
}
});
});
Now, whats happening.
The function for the 'edge.remove' event works smooth and without any problems.
But when the user click like the code simply dont run on the success part of the ajax call, i tryed a simple alert like alert('test'); but nothing happens too. The code, however, works fine on the backend and the code I want to add is added with success.
However if i set the async : false the code works, the alerts is presented on the page but the browser gets that nasty "lock down" that i really want to avoid.
So, anyone have any idea whats exactly going on here?
PS.: Theres 2 others facebook elements on this page, the comments and activity feed. I dont know but im with the impression that the activity feed may have something to do with this...
I think this is some sort of scope issue. If you define the function containing the ajax call outside of the scope of the FB.Event.subscribe, and just call that function from within the FB.Event.subscribe, that may fix the issue.
HI i was facing the same problem but for different FB event. Here is my code an it 100% working :-
<!doctype html>
<html lang="en" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta charset="utf-8">
<title>Facebook Like Button</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>--->(DO not forget to include)
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: '464134126954048', status: true, cookie: true,xfbml: true});
FB.Event.subscribe("message.send", function(targetUrl) {
$.ajax({
url:'abc.php',
type:'POST',
data:{name:'sunlove'},
success:function(data)
{
alert("I am here");
}
});
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<fb:send href="http://demo.antiersolutions.com/studybooster1.2"></fb:send>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"> </script>
</body>
</html>
You can just copy and make new file and customize according to your need
i am working on a small application in asp.net, c# in my website, which shows user is logged into facebook in the same browser. Which means in the browser if user open my website(in same browser if user is not logged into facebook) a popup should show that user is not loggedin. if the user logged into facebook then a popup should come in my website showing that loggedin after refresh of my page.
in a page refresh i just want to alert the login status of user...
i had the xd_receiver.htm file in my root directory and
this script in header and
Untitled Page
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
type="text/javascript"></script>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js#appId=142899075774321&xfbml=1"></script>
<script type='text/javascript' language='javascript'>
window.onload = function() {
FB.init('142899075774321', 'xd_receiver.htm');
alert("Before ensureInit");
FB.ensureInit(function() {
alert("After ensureInit");
FB.Connect.ifUserConnected(onUserConnected, onUserNotConnected);
});
};
function onUserConnected() {
alert('connected!');
window.location.reload();
}
function onUserNotConnected() {
alert('not connected');
}
</script>
this script in body....
But this code is not working.....
how should i solve this......
thanks in advance
Try this for the html head part:
<title>Facebook Status</title>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"
type="text/javascript">
</script>
<script type="text/javascript">
var api_key = 'Your app id';
var channel_path = 'xd_receiver.htm';
//alert(document.referrer);
FB_RequireFeatures(["XFBML"], function() {
// Create an ApiClient object, passing app's API key and
// a site relative URL to xd_receiver.htm
FB.Facebook.init(api_key, channel_path);
FB.Connect.get_status().waitUntilReady(function(status) {
switch(status) {
case FB.ConnectState.connected:
document.getElementById("divstatus").innerHTML ="LOGGED IN AUTHORIZED";
break;
case FB.ConnectState.appNotAuthorized:
document.getElementById("divstatus").innerHTML ="LOGGED IN NOT AUTHORIZED";
break;
case FB.ConnectState.userNotLoggedIn:
document.getElementById("divstatus").innerHTML ="NOT LOGGED IN";
break;
}
});
});
</script>
Then use this for the html > body part:
<div id="divstatus">
</div>
I want to check if my users are fans of my facebook page. I think something like this should do it:
<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"></script>
<script type="text/javascript">FB.init("my api key","xd_receiver.htm");</script>
<script type="text/javascript">
//<![CDATA[
FB_RequireFeatures(["Api"], function(){
var api = FB.Facebook.apiClient;
api.pages_isFan(PAGE_ID,gigyaUser.FACEBOOK_USER_ID,function(response){
alert(response);
});
});
//]]>
</script>
However, for some reason I keep getting null even though the user is in fact a fan of the page. Am I missing something?
I think you almost had that correct.
This snippet works great for me.
assumes:
1. fanPageUID = the fan page's uid
2. and user UID is the UID of the user
3. (and you have an active session)... this may be the hard part, but not part of this question.
function checkifFan() {
FB_RequireFeatures(["Api"], function(){
var api = FB.Facebook.apiClient.pages_isFan(fanPageUID,userUID,function(response){
if (response==false) {
setTimeout('checkifFan()', 300); //every 300ms check if they have pressed fan
}
else {
location.reload();
}
});
});
}
You can also check that a user is a fan of your website by the following script:
<fb:login-button scope="user_likes">
Grant Permissions to Allow access to Likes
</fb:login-button>
<button onclick="checkDoesLike()">Check if user Likes the Page</button>
<h1>Like this Application's Page</h1>
<fb:like-box profile-id="your_page_id"></fb:like-box>
<script>
window.checkDoesLike = function() {
FB.api({ method: 'pages.isFan', page_id: 'your_page_id' }, function(resp) {
if (resp) {
Log.info('You like the Application.');
} else {
Log.error("You don't like the Application.");
}
});
};
</script>