Your app's Canvas page doesn't load - facebook

I have a Facebook App (a game) that is perfectly working if I access the URLs directly (https://apps.facebook.com/[appnamespace]/ or https://mydomain.com/, the last one being the canvas URL).
But every time I submit the app for review I get the following feedback: "Please address the following feedback from our review team. Once you have made the changes listed below you may resubmit for review." and "Your app's Canvas page doesn't load".
Problem is I don't really know what to change because for me and for friends with whom I shared the link it's working as expected.
I have only one error in the console in Chrome which is:
"Unsafe JavaScript attempt to access frame with URL https://apps.facebook.com/[appnamespace]/ from frame with URL https://mydomain.com/. The frame being accessed set 'document.domain' to 'facebook.com', but the frame requesting access did not. Both must set 'document.domain' to the same value to allow access.
I don't have document.domain specified in my page though I tried some values before to get rid of this error message without success. And every time I set a value for document.domain I get another error in the console: "Uncaught Error: SecurityError: DOM Exception 18".
I didn't find anything on this that is working.
So any help/hint would be appreciated. I also tried to ask for more detailed feedback in the review description message but I still get the same message with no clue on how to solve the problem.
Thanks.

So I finally solved the issue.
The problem was that I didn't test the app when the user is not connected to Facebook. For me the app was not supposed to be used outside Facebook game center (though it's possible) and Facebook probably test this case during app review. Hence none of the following events gets fired:
auth.statusChange
auth.authResponseChange
auth.login
To tackle this problem I make a call to getLoginStatus, something like this:
FB.getLoginStatus(function (response) {
console.log('[Facebook] getLoginStatus: ' + response.status);
if (response.status !== 'connected' &&
response.status !== 'not_authorized')
{
console.log('[Facebook] not connected');
$('#loginscreen').show();
$('#btn-fb-login').click(function (event) {
event.preventDefault();
FB.login(function (response) {
$('#loginscreen').hide();
start(response);
}, { scope: 'email,publish_actions'});
});
}
});

Related

Error while subscribing page to Facebook App - Code 200 (Insufficient Permission)

I'm attempting to set up a way to retrieve Facebook Lead Ads as per instructions given here: https://developers.facebook.com/docs/marketing-api/guides/lead-ads/retrieving/
However on subscribing a page to the App, I'm getting the following error on printing the response:
code: 200
error_subcode: 1373034
error_user_msg: "You do not have the necessary permission for the
specified Page to perform the requested action."
error_user_title: "Insufficient Permission"
fbtrace_id: "CLbnoml6VX1"
is_transient: false
message: "Permissions error"
type: "OAuthException"
Here is the segment of code used to subscribe the app:
function subscribeApp(page_id, page_access_token) {
console.log('Page Access Token:'+page_access_token);
console.log('Subscribed Page to FB Leads Live Update. Page ID: ' + page_id);
FB.api('/' + page_id + '/subscribed_apps',
'post',
{access_token: page_access_token, subscribed_fields: 'leadgen'},
function(response)
{console.log('Successfully subscribed page', response);
});
}
I suspect that the page being subscribed is in question here (as the error states), and must be set accordingly to be subscribed to my app. I should state that the page is already subscribed to another app, and I'm using this page for testing purposes on my second FB App for another web application. Any insight would be appreciated!
Same situation.
Your assumption is correct. You can't have 2 apps attached to capture leads.
Once the other app is disconnected and enough time has passed (No explanation of how long), permissions will be set correctly

Facebook getLoginStatus() function and phonegap not updating status

I am currently developing an app on Android using phonegap and would like to use Facebook in the app. I have created an app on Facebook called say "Test". When I am not logged into "Test" but I am logged into Facebook (Facebook app on the Android device) and run the getLoginStatus() function I get a response of unknown instead of not_authorized. Thus my first question is this intended? Am I meant to get a response of unknown or is this an error from phonegap and I'm meant to get a response of not_authorized.
The second question is, when I login into the Facebook app called "test" everything runs as it should (Facebook user gets registered for "test"). When I call the getLoginStatus() function it works perfectly fine and says I'm connected with no problems.
BUT
If I go into Facebook and remove the app "test" from my FB account and then run the android app again and run the getLoginStatus() function is STILL says that I have the app "test" registered to my Facebook account but this is no the case!! Note that I do in the code make sure that I call the server every time instead of using a cached result by the JS SDK. Now my Second question is. Is this meant to happen? Or if not is it a Facebook or Phonegap problem (Phonegap either keeps getting the cached response or Facebook doesn't update their side quick enough?)
Here is code:
function getLoginStatus()
{
FB.getLoginStatus(function(response)
{
alert(JSON.stringify(response));
alert(response.status);
if (response.status == 'connected')
{
alert('logged in');
FB.api('/me',function (response) {
if (response.error)
{
alert('There is an error');
}
else
{
alert(response.name);
}
});
}
else
{
alert('not logged in');
}
},true);
}
Any response would really really be appreciated!!
When I am not logged into "Test" but I am logged into Facebook (Facebook app on the Android device) and run the getLoginStatus() function I get a response of unknown instead of not_authorized.
not_authorized: You get not_authorized when the user is logged into facebook but has not authorized your app. If you transfer the guy to facebook homepage, he enters username and password and cancels authorization, thereafter you get not authorized. IF the guy is logged into facebook,and your app hasn't transferred him to fb to authorize yet, you still get not authorized
https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
unknown: If the user is not logged into facebook, you get a status of unknown.
So logged in, not authorized : not_authorized
Not Logged in: unknown
If I go into Facebook and remove the app "test" from my FB account
I am guessing it takes a while for these changes to propogate. If the user has authorized the app in the current context, it will stay authorized for a while(or until he logs off). I don't think there's anything wrong with this personally
This is not a phonegap issue. unknown is one of the valid responses from the getLoginStatus function. See the facebook API documentation for information about this funciton. There, they describe the unknown response as:
the user is not logged into Facebook at this time and so we don't know if they've authenticated your application or not (unknown)
As to your second question, the problem you are seeing is because by default, the getLoginStatus function caches its response for performance reasons. However, they provide you with a way to force a refresh of the status. You can do this by passing a second parameter, Force into getLoginStatus.
FB.getLoginStatus(function(response) {
// this will be called when the roundtrip to Facebook has completed
}, true); // The second parameter, called 'force' by default is False. True signifies that you want to force a call to the server so you can see the latest login status.
You can read more about that Force parameter by looking at the above API documentation link and searching for the 'Force' parameter.
By the way, I had temporarily deleted the answer as I had answered without knowing how to respond to the second question, but undeleted it after finding out the reason behind your issue.

PhoneGap; FB Connect Plugin (Android OS): Re-Authorizing FB App every post

I created an Android App with PhoneGap:Build and the FB Connect Plugin. The app works fine and the FB Plugin, too. Just one tiny thing isn't working yet. I won't to post something after submiting a button which works, too. At the first time the user has to login and grant permissions to the FB App and them the post is published. That's the way it should be. And the next time the user submits the post should be published without the whole permission thing but this isn't working!? FB shows a message like "You already granted permission ... to the app." and the user has to push the Ok-button before the post is published???
Because I still haven't found an answer for my question, maybe I just do something wrong in my FB Javascript call? Here is the current code:
FB.login(function(response) {
if (response.authResponse) {
var data = {
...
}
FB.api('/me/feed', 'post', data, function(response) {
// Callback
if (!response || response.error) {
// ERROR
}
});
} else {
// ERROR
}
}, {scope: 'publish_stream'});
Well, to better understanding here a picture of the screen that apears every post:
http://i.stack.imgur.com/bZrde.png
Thx,
Daniel
I think the solution to this problem is to not include the login request every time you want to post something. You can check login status, and/or permissions, without performing a login. Then, if the user is not logged in, do the login first, and come back to the new post action.

Facebook UI, how to check if a user can send facebook message to another user

I want to follow up this question. I use FB.ui to send link and got exactly the same error for some users. Is there anyway to check it and decide whether to display the ui to the user ?
API Error Code: 100
API Error Description: Invalid parameter
Error Message: Viewer cannot message specified recipients.
<a href='#' onClick="
FB.ui({
method: 'send',
link: 'http://www.xxxxxxxxxxx.com',
to: ###########,
});
">Send a message</a>
Even when I use the url send method, some user does not work. For example:
Error User : https://www.facebook.com/dialog/send?app_id=123050457758183&name=People%20Argue%20Just%20to%20Win&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/&to=100000104626944
Normal User: https://www.facebook.com/dialog/send?app_id=123050457758183&name=People%20Argue%20Just%20to%20Win&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/&to=1311251197
(this is the share link example taken from https://developers.facebook.com/docs/reference/dialogs/send/)
bug reported to facebook: https://developers.facebook.com/bugs/538638372825668
Edit: in fact, everyone should be reachable through messages now. It's only there are new "filtering preferences". I guess this can_message field is now useless because it should always return true. I think it is going to be deprecated in a while.
In the user FQL table, you have a field that must verify what you need:
can_message (boolean): whether the user can send a message to another user
Source: https://developers.facebook.com/docs/reference/fql/user
select can_message from user where uid=USER_ID
USER_ID being the person that your app user want to send a message to.
You can use the FB api;
I use something like:
FB.api('/me/permissions', function (response)
{
//check contents of response for required permissions here
fb_publish_perm = response.data[0]['publish_stream'] ? response.data[0]['publish_stream'] : false;
if (fb_publish_perm)
{
// it permissions exist
}
else
{
// permissions dont exist launch the ui to request.
}
});
Please treat the above as psedo code, as it came straight off the top of my head!

Uploading Image With Facebook JS SDK

I've put together a script, with the help of another SA post, but the issue I'm having is it's always returning error. When logging the error with console log it contains no properties so I can't determine why I am getting the error.
$(".add-image").click(function() {
FB.login(function(response) {
if (response.authResponse) {
var imgURL="http://farm4.staticflickr.com/3332/3451193407_b7f047f4b4_o.jpg";
FB.api('/album_id/photos', 'post', {
message:'Test',
url:imgURL
}, function(response){
if (!response || response.error) {
console.log(response);
} else {
alert('Post ID: ' + response.id);
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'publish_stream'});
});
I've created the app. Added the API ID when including the Javascript.
When running I get a pop up asking me to log in, and it seems to log me in without problems. But it returns an error when checking for a response or response.error.
Any advice.
Not sure if this is still a problem for you, but I've been looking into the same thing recently and I believe that, for this type of upload, FB basically requires source to be the image data itself, not a URL to the image. (See the create photos section on https://developers.facebook.com/docs/reference/api/album/ - it indicates that the source paramater must be multipart/form-data.)
So you have a few workarounds:
1) You may be able to do it from JS if you can create a custom Open Graph Object. I haven't tried this yet, but https://developers.facebook.com/docs/opengraph/usergeneratedphotos/ looks like it expects a URL rather than the post data itself.
2) If the image is originating on the user's computer, you can create an HTML form that submits to FB and have the image go directly from the user to FB without ever hitting your server. This blog post shows an example of that: https://developers.facebook.com/blog/post/498/
3) If the image is originating in your system, you can do a POST from your server to FB that mimics the above form. If it's somewhere else online (such as Flickr), you can download it to your system first and then POST it to FB. You'll have to include an access_token in the request. I don't know what language / framework you're using on your server, but there's probably a library to make creating POST requests easier.