i am making a facebook application, everything seems done.
here is the sample flow(index.php):
seekpermission.php
processinfo.php
generateresult.php
poststatus.php(the javascript way as told in the documentation)
invitefriends.php(the javascript way as told in the documentation)
hope the names are self explanatory.
the trouble is the dialogue to update status and invite friends comes almost parallely, but what i want is once the user publishes/skips the status message only then should the dialogue of invite friends should come. here is what i tried but it is not working, please help thanks!
FB.ui(
{
method: 'feed',
name: 'name goes here',
link: 'http://apps.facebook.com/****/',
picture: '<?php echo $imageurl; ?>',
caption: 'here is caption',
description: 'the description',
message: '<?php echo $charecter; ?>'
},
function(response) {
if (response && response.post_id) {
alert('<?php include "invitefriends.php"; ?>');
} else {
alert('<?php include "invitefriends.php"; ?>');
}
here is the invitefriends.php
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'2****', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'apprequests',
message: 'Folks check out my new facebook app!! visit http://apps.facebook.com/**** '});
</script>
</body>
Well, that's a weird way to accomplish a simple task:
You can combine step 4 & 5 in one step:
FB.ui(
{
method: 'feed',
name: 'name goes here',
link: 'http://apps.facebook.com/****/',
picture: '<?php echo $imageurl; ?>',
caption: 'here is caption',
description: 'the description',
message: '<?php echo $charecter; ?>'
},
function(response) {
FB.ui({ method: 'apprequests',
message: 'Folks check out my new facebook app!! visit http://apps.facebook.com/**** '});
/* if (response && response.post_id) {
alert('<?php include "invitefriends.php"; ?>');
} else {
alert('<?php include "invitefriends.php"; ?>');
} */
}
)
As you can see no need for the if else since you will force the invite anyway!
Now if you really need to use your approach, then you may use something like (in the response:
location.href='<?php echo 'path/to/invitefriends.php';
IMPORTANT NOTE:
Most likely ALL your 5 steps can be combined in ONE file, this is better because:
You don't need to load and initialize the JS-library FIVE times!
Will be a better user experience instead of loading each time
You can wrap all the Facebook Calls in JS functions and just call each one in the response of the previous one!
Related
I am using FB UI for sharing using feed method.
The page is sharing correctly.
Can anyone tell how to hide the share via "Facebook Application Name" link.
I'm using following code.
FB.ui(
{
method: 'feed',
name: '<?php the_title(); ?>',
link: '<?php echo $urlofpage; ?>',
picture: '',
caption: '<?php echo bloginfo('siteurl'); ?>',
description: '',
message: ''
},
function(response) {
if (response && !response.error_code) {
if ( response && response.post_id ){
$.ajax({'url' :'http://graph.facebook.com/?id=<?php echo $urlofpage; ?>','success':function(data){
get_like_count(data.shares);
}});
}
}
}
);
You can´t hide that text, and it´s very important anyway. People should know if something got posted via an App and not by the user directly.
Using the example from the developer site:
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
I get the following back:
Error: element not specified
innerError: undefined
message: "element not specified"
At first I thought I was missing the "fb-root" element, but I have it in my body:
<body onLoad="onLoad()">
<div id="fb-root"></div>
</body>
Now I'm thinking it has something to do with my Backbone/jQuery Mobile usage, because the body is cleared once the first page is loaded. However, the FB object is loaded, so I really don't know what's wrong. Any ideas to try and fix this?
Thanks.
I had the same issue and I figured out that was happening just with Chrome. Which browser are you using?
What worked for me was specifying
display: 'popup'
inside FB.ui {}
At the moment I check the browser and if Chrome I use 'popup', if not 'iframe'
var display = 'iframe';
if (navigator.userAgent.toLowerCase().indexOf("chrome") != -1){
display = "popup"
}
FB.ui({
method: 'share',
display: display,
href: 'https://developers.facebook.com/docs/reference/dialogs/'
},
function (response) {}
);
Should work also with feed, but I haven't tested it yet.
i want to redirect users to a specific page after they share on facebook, i have found a good answer here at:
redirect user after facebook share and publish
here's the script
<script type="text/javascript">
FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});
function share_me() {
FB.ui({
method: 'feed',
app_id: 'YOUR_APP_ID',
link: 'SHARE_URL',
picture: 'PIC_URL',
name: 'SHARE_NAME',
caption: 'SHARE_CAPTION',
description: 'SHARE_DESCRIPTION'
},
function(response){
if(response && response.post_id) {
self.location.href = 'SUCCESS_URL'
}
else {
self.location.href = 'CANCEL_URL'
}
});
}
</script>";
<div onclick="share_me()">Share</div>
but when i used the script ,there's no redirect at all, even if the user click "cancel"
please help me with this as am searching for a method like this since 1 week!
Try using another javascript function for redirecting like window.location = "YOUR_PAGE"
The invitation dialog pops up fine and invitation is also sent. But i am unable to redirect the user to desired page after sending the invitation using redirect_uri as stated in Requests Dialog facebook documentation (https://developers.facebook.com/docs/reference/dialogs/requests/). There is no redirection or anything after sending invitation.
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'app_id',
});
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'Invite friends!',
request_uri: 'https://apps.facebook.com/myappname/invitesent.php', data: '<?php echo $user_id; ?>', exclude_ids: [<?php echo $friends; ?>]
}, requestCallback);
}
function requestCallback(response) {
// Handle callback here
}
</script>
You don't need the redirect_uri if you are using the JS-SDK. This is the job of the callback function, so in your requestCallback():
function requestCallback(response) {
// Handle callback here
...
// once done, redirect (outside of Facebook page!)
top.location.href = 'http://mydomain.com/nextpage/';
}
Or I suppose location.href = ''; to stay in the Facebook app frame.
As you have already included Facebook javascript SDK in your App
and you have writen this code for inviting friend for your App in a script
FB.ui({ method: 'apprequests',
redirect_uri: 'APP URL',
message: 'My Message'
});
This will redirect to App URL without redirecting to Facebook canvas URL.So this will not work even if you use data parameter such as
FB.ui({ method: 'apprequests',
data: 'APP URL',
message: 'My Message'
});
Write this code at your App landing page i.e. in index.php at beginning of the code.
$requestid=$_GET[request_ids];
if(!empty($requestid))
{
echo "<script> window.top.location.href='APP URL'; </script>";
}
Have you given callback canvas url when you create facebook application?
I'm creating an iFrame app on Facebook which is basically just a Mailing List sign up page. However, when people click Sign Up, the FB:ui "Post To Your Wall" pops up and gives the user the option to share what they have just signed up for if they want to. It works fine.
However, I want to find a way to display the FB:ui ONLY to users who are logged into Facebook. My app shouldn't require any permission from users as it is simply a landing page that gives people an option to share if they want to. There's never any automatic sharing done.
I'm using the below code currently:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'my app id', cookie:true,
status:true, xfbml:true
});
FB.getLoginStatus(function(response) {
if(response.session) {
sharethisnow();
} else {
// no user session available, someone you dont know
if(response.status == "notConnected") {
// But user is logged into facebook
sharethisnow();
} else {
// User is not logged into facebook
}
}
});
function sharethisnow() {
FB.ui({ method: 'feed',
link: 'my link',
name: 'my page name',
caption: 'my caption',
description: 'my decription',
picture: 'my picture',
message: 'my message'});
}
</script>
As you can see, I'm attempting to run the FB:ui (sharethisnow function) only to users who are either logged into Facebook AND my app, or logged into Facebook only. But for some reason the code above is only working for page-admins. When I log in as an admin, I sign up and the FB:ui pops up as it should do. However, when I view the page as a non-admin (just a general logged in Facebook user), the FB:ui pops up but says that there is an error and to "please try again later".
It's working fine for me, maybe check the Page settings (private/public). Also try this simpler code first:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'APP_ID', cookie:true,
status:true, xfbml:true
});
FB.getLoginStatus(function(response) {
if(response.status == "unknown") {
return;
}
sharethisnow();
});
function sharethisnow() {
FB.ui({
method: 'feed',
message: 'my message'
});
}
</script>