FB.UI apprequests inside a frame causes script access denied error - facebook

I am working on an application, which is iframed into another application (different domain). My application which is in the iframe has apprequest functionality implemented. For some reason, whenever I invoke the apprequest dialog, I get a script access denied error.
The following are all the details:
App A --> is in domainA
App B --> is in domainB and is Iframed in to App A.
App B has a button which invokes, the following code:
FB.login(function (resp) {
FB.ui({
method: 'apprequests',
message: msg,
display: 'iframe',
access_token: resp.authResponse.accessToken
}, fbRequestCallback);
});
This throws an error. Please help.

If a user clicks 'Accept' on a Request, they will be sent to the Canvas Page URL of the app that sent the Request. So the request will always be sent back to App that generated the request. You will then have to read the request at:
https://apps.facebook.com/[app_name]/?request_ids=[request_ids]
and redirect it accordingly.

Related

Facebook Feed Dialog does not work on Chrome/Android native app

I am developing a Facebook Canvas App which allows user to post a link to their wall:
function postFeed(){
FB.ui({
method: 'feed',
link: 'https://apps.facebook.com/?????',
name: '?????',
description : '?????',
picture: '?????',
}, function(response){});
}
It works fine on desktop (all browsers including desktop Chrome) and mobile Firefox. However when I use mobile Chrome or Android Facebook App's internal browser to open it, the following message shows up when I run postFeed() and be redirected to the feed dialog:
An error occured. Please try again later.
API Error Code: 110
API Error Description: Invalid user id
Error Message: Missing user cookie (to validate session user)
postFeed() is called after I run the following code:
FB.login(function(response) {
if (response.authResponse) {
alert("Welcome!");
}
}, {scope: 'public_profile'});
However if I remove the above code, the error message disappears and I can see the feed dialog normally.
Is there any possible reasons/solution that can solve the problem but without removing the above code?
Thank you very much.
I use 'share' instead of 'feed' method and the problem is gone.

How to get the data param in an app generated request for a facebook user

I am sending an app generated request to a user(already authorized the app) by calling the below function
function send_app_request(){
FB.api( "/" + '<USER-ID>' + "/apprequests", "POST", {
message: "Custom Request for you!",
data: "<REDIRECT-APP-URL>",
access_token: "<APP-ACCESS-TOKEN>"
}, function(response) {
console.log(response);
});
}
When a user clicks on the pop-up that appears beneath the app icon(with a red number) at the top right corner of the canvas, he gets redirected to the index page of the canvas with 'request_ids' as one of the parameters. How do I get/decode the 'data' parameter(contains a url) which i passed during the FB.api call(in the function above), so that I can redirect the user to a specific location(url) in my application.
I have seen this functionality in many applications, and I am "unable" to figure out how they are able to redirect the users to a specific location in their app, instead of the index page when the user clicks on the pop up.
The data is specific for that request you send to the user.
When the user clicks the requests and gets to your page (with the "request_ids" parameter) you should then get the data for the requests.
The url to get the requests from:
https://graph.facebook.com/USER_ID/apprequests
You will get a list of the requests and the data for each one (if such was sent).
You then need to delete the request for the user by issuing a request to:
https://graph.facebook.com/REQUEST_ID?method=delete
You can find a php example here: Upgrade to Requests 2.0

Facebook JS SDK - Request UI

I am trying to create a Facebook Request Dialog with JS SDK inside a Facebook page iframe tab. The dialog shows up, I can select people from my friends, I get no error not even after I click "Send Request", but my friends don`t receive the notification. This is my code:
FB.ui(
{
method: 'apprequests',
message: 'request'
}, function(response) {
console.log(response);
});
LATER EDIT: I uploaded a file with exactly their code from documentation on this tab: http://www.facebook.com/pages/WebTest/255282254520859?sk=app_230016043737427 , and my friends still can`t see the requests.
Have you run it with a Firebug / Chrome console open? Maybe an exception is being generated and dumped there.

How can I redirect to my app page after accepted a app request sent from our app?

I have a issue for facebook apprequests (oauth2, graph)
I sent a app request to my friend B.
B logged into facebook and found our request in the app list.
B clicked the accept button
B redirected to the facebook canvas page. I want to rediect to our app, not facebook's canvas, is this doable?
thanks
you can put a url in the data param
see here http://developers.facebook.com/docs/reference/dialogs/requests/ under properties at bottom.
data Optional, additional data you may pass for tracking. This will
be stored as part of the request objects created.
This will get passed back to you and you can use javascript to location.href to the url in the data.
----------Here is a sample i have used in the past
var thisimg = 'AN_IMG';
var thisurl = 'A_URL';
window.sendrequest = function(){
FB.ui({ method: 'apprequests',
title: 'A request.',
message: 'Rate Me! Request from: ' +thisname+' ',
data: ''+thisimg+' '+thisurl+' ',
filters: ['all'],
});
}
---------- Sample from Facebook with data param added.
var thisimg = 'AN_IMG';
var thisurl = 'A_URL';
function sendRequestToManyRecipients() {
FB.ui({method: 'apprequests',
message: 'My Great Request',
data: ''+thisimg+' '+thisurl+' ',
}, requestCallback);
}
function requestCallback(response) {
// Handle callback here
}
upon callback you can do a window.top.location.href=''; with the url you passed in data.
NOTE: The default redirect for a request is the canvas, this cannot be changed. After user lands on your canvas you will read the data param from the request and redirect them to your external app.
"i do not see any other way to do this, since requests2.0 does not include option for a redirect uri."
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
$requestid=$_GET[request_ids];
if(!empty($requestid)) {
echo "<script> window.top.location.href='APP URL'; </script>";
}
This is an old question, but now there is a simpler solution.
In the Facebook app settings under "Facebook Canvas" there is a field titled "Mobile Site URL". When a user tries to open your canvas app from a mobile device (s)he will be redirected to that URL.
That URL should point to a page from which you should redirect to the App Store or Play Store (or coming soon page) based on the browser user agent.

Facebook AppRequests redirect user to a Page Tab

When sending an AppRequest using from a page Tab:
FB.ui({
method : 'apprequests',
message : 'message',
title : 'Friend'
}, function (response){}));
I want the receiving user to be directed to the page tab and not the canvas application page.
is there a redirect_uri parameter that's no documented or should I just do a hard refresh on the canvas?
Also would like to know if I can force the user to select only one friend in this dialog in used to be possible in the old requests widget?
Thoughts appreciated
If a user clicks 'Accept' on a Request, they will be sent to the Canvas Page URL of the app that sent the Request. This URL will contain an additional GET parameter request_ids, which is a comma delimited list of Request IDs that a user is trying to act upon:
https://apps.facebook.com/[app_name]/?request_ids=[request_ids]
You can the redirect to the fan page tab.
Atul Agrawal, Founder, ascratech.com
I've done this by setting up a requestCallback method, a JavaScript method that gets called after completing the dialogue.
FB.ui({method: 'apprequests',
message: 'Requests are fun.',
display: 'iframe',
access_token: ACCESS_TOKEN,
}, requestCallback);
function requestCallback(response) {
// Handle callback here
window.location = "URL_FOR_RESPONSE_ACTION";
}