Problem with the redirections of apprequest in php - facebook

I am using the code below to send an app request to someone.
It works fine; it displays in Facebook notification.
when I click that notification, it redirects to the facebook app page.
I'm unable to make it redirect to the page which exists list of facbook app requests.
How do I make it redirect there?
is there any need to do changes in my facebook app setting ?
<div id="fb-root"></div>
<script>
function FacebookIframeAuthenticator(){
window.fbAsyncInit = function() {
FB.init({
appId: '123456789',
status: true,
logging: false,
cookie: false,
xfbml: true
});
FB.Canvas.setSize({height: 2000});
FB.Canvas.scrollTo(0,0);
FB.Canvas.setAutoResize();
};
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);
}
new FacebookIframeAuthenticator();
function sendInvReq ( friendUid, event ){
FB.ui({
method: 'apprequests',
message: 'I\'d like you to join my professional network on SITE NAME .- DB',
to: friendUid,
data: ''
}
, function(r){
if (r != null && typeof(r) != 'undefined'){
if (r.request_ids){
FB.api('/me/apprequests/?request_ids='+toString(request_ids));
$.ajax({
url: 'http://exapmple.com',
cache:false,
type:'POST',
data:({requestIds: r.request_ids.join(','), x_csrf: csrf}),
dataType: 'json',
complete: function(transport){}
});
}
}
}
);
}
</script>

in your developers page (https://developers.facebook.com/apps/your_app_id/advanced) you must change your application advanced settings "Upgrade to Requests 2.0" to disable

If I understood your question right: you can't control the notification url. It will always automatically redirect to your app url with one or more request_ids as paramter. The only possibility to redirect to your prefered destination is to look for this parameter and react properly.

Related

Facebook application only accessible by admin user account

I created a facebook app to share articles from a website. When I'm connected from the app's admin account, I can share articles, but when I try to share articles from another account, this error is displayed: An error has occurred, please try again later
This is the used script:
<script>
window.fbAsyncInit = function() {
FB.init({appId: '1488318304714792', status: true, cookie: true,
xfbml: true});
};
(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_single_post').appendChild(e);
}());
$(document).ready(function(){
$('.share_button_single_post').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: '<?php echo utf8_encode(strtoupper($chaine2)); ?>',
link: $("input[type='hidden'][name='"+this.id+"1']").val(),
picture: 'http://www.bdo.com.tn/BDO-facebook-logo.png',
caption: 'www.bdo.com.tn',
description: $("input[type='hidden'][name='"+this.id+"2']").val()+'...',
message: ''
});
});
});
</script>
You'll need to check you're not in sandbox mode first.
Have you gone to "Status and Review" in the option panel on the left, and then clicked "yes" for the question "Do you want to make this app and all its live features available to the general public?"
This should make the app accessible to all FB users.

wall post on facebook from hybrid mobile application

I am having a hybrid mobile application(should work in android and ios). In which I need to post on facebook wall from my application. Please note its a hybrib app, so I am not supposed to use any java or c code.
I tried the following method , its working in simulator , but not in actual device. Please help me.
<script>
window.fbAsyncInit = function() {
FB.init({
appId : ' my appID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#share_button').live('click', function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: 'HyperArts Blog',
link: 'http://hyperarts.com/blog',
picture: 'http://www.hyperarts.com/_img/TabPress-LOGO-Home.png',
caption: 'I love HyperArts tutorials',
description: 'The HyperArts Blog provides tutorials for all things Facebook',
message: ''
});
});
});
</script>
Thanks
I ran into this. your:
document.location.protocol
which is suppose to pull in the FB SDK is actually "file:///" and thats what gets fed into the url for that FB JS library.
Manually specify http:// or https://
This didnt work for me either on safari webView on IOS so i had to hit the endpoints manually using AJAX.

Apprequests from a Website

Is there any way to send apprequests if your application is a website?
I reported a bug on facebook http://developers.facebook.com/bugs/182553325173000 but I do not know if this is possible or not
yes you can do this by adding the JS API,
before <body> add:
<script type="text/javascript">
function inviteFriends(){
var receiverUserIds = FB.ui({
method : 'apprequests',
message: 'YOUR CUSTOM MESSAGE',
},
function(receiverUserIds) {
console.log("IDS : " + receiverUserIds.request_ids);
}
);
}
</script>
after the <body> include the API (asynchronous method):
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true //enables OAuth 2.0
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
and call it:
or
You can do that with the Javascript SDK
it is in the documentation:
https://developers.facebook.com/docs/reference/dialogs/requests/
It's possible, as the other answers have shown, but the user will be brought to your canvas app when they accept the requests

How get facebook avatars use https protocol?

I use old FB API in my project.
For showing FB avatar I use facebooker gem in my Rails app. I user facebooker method "fb_profile_pic(owner, {:linked => false, "facebook-logo" => :true}". He generate this FBML:
<fb:profile-pic facebook-logo="true" height="73" linked="false" size="square" uid="1440313044" width="73" style="width: 73px; height: 73px; " class=" fb_profile_pic_rendered"><img src="http://external.ak.fbcdn.net/safe_image.php?d=d5eee08e09b7573d93b61f82ac11feda&url=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fhprofile-ak-snc4%2F41642_1440313044_4069_q.jpg&logo&v=5" alt="Shaliko Usubov" title="Shaliko Usubov" style="width:73px;height:73px;" class=""></fb:profile-pic>
If I display this avatar on the page which is available at https protocol - getting error
"The page at https://my_domain.com/ displayed insecure content from http://external.ak.fbcdn.net/safe_image.php?..."
How can I get FB avatar with HTTPS protocol?
/* ATTENTION BELOW */ says if your your app https then fb javascript libary will be https.
You may check in your code
window.fbAsyncInit = function () {
FB.init({ appId: /*123456789*/', status: true, cookie: false, xfbml: true });
};
(function () {
var e = document.createElement('script'); e.async = true;
/* ATTENTION BELOW */
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());

Facebook Graph API: FB.login() called before calling FB.init()

I'm trying to use the new Facebook Graph API on my website. This is what I have:
Somewhere on the page:
<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>
Right after the tag:
<div id="fb-root">
</div>
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({ appId: '<%= ConfigurationManager.AppSettings["FBAppId"] %>', status: true, cookie: true, xfbml: true });
/* All the events registered */
FB.Event.subscribe('auth.login', function (response) {
// do something with response
alert("login success");
});
FB.Event.subscribe('auth.logout', function (response) {
// do something with response
alert("logout success");
});
FB.getLoginStatus(function (response) {
if (response.session) {
// logged in and connected user, someone you know
alert("login success");
}
});
};
(function () {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
} ());
</script>
but when I click on the generated login button, nothing happens.
In addition, I'm getting
FB.getLoginStatus() called before calling FB.init().
in Firebug console.
Any ideas?
I can't believe it, I was referencing a non existing key in the Web.config hence FB.init was failing silently.
It works as expected now.
To be clearer I wasn't passing the appId to FB.init, once I did, it worked.
Had the same issue, here is the solution that worked for me. Just put the following in your head section or in other words, add the app_id to the source of the facebook js.
<script src="//connect.facebook.net/en_US/all.js&appId=xxxxxxxxxxxxxxx" type="text/javascript"></script>
In my case, the problem went away after I disabled the XFBML functionality (i.e. setting the xfbml key to false, removing the fb: namespace and the #xfbml=1 fragment in <script src="…">). Good that I didn’t need it anyway.
YMMV, there are several other valid reasons why this error message can appear.