0
votes

I have followed the facebook developer tutorial in order to do this to no avail.

Basically I need user to authorize my app from within a page tab.

I have used their recommended javascript to redirect the user on page load to redirect them to the oauth popup however when the app loads I just get the dreaded "sorry an error occurred"

The URL that is generated is "https://www.facebook.com/dialog/oauth/?client_id=247274355370447&redirect_uri=https%3A%2F%2Fwww.facebook.com%2Fpages%2Fnull%2F286793781401206%2F247274355370447&scope=email,user_about_me" so I can see my variables for both page_id and app_id are being passed in.

Here is my complete JS code

<script>
var oauth_url = 'https://www.facebook.com/dialog/oauth/';
oauth_url += '?client_id=<? echo $app_id;?>';
oauth_url += '&redirect_uri=' +     encodeURIComponent('https://www.facebook.com/pages/null/<?php echo $page_id;?>/<?php echo $app_id;?>');
oauth_url += '&scope=email,user_about_me'
window.top.location = oauth_url;
</script>
3

3 Answers

2
votes

I am having the same issue.

You should be able to do this.

The URL to redirect to after the user clicks a button in the dialog. The URL you specify must be a URL of with the same Base Domain as specified in your app's settings, a Canvas URL of the form hxxps://apps.facebook.com/YOUR_APP_NAMESPACE or a Page Tab URL of the form hxxps://www.facebook.com/PAGE_USERNAME/app_YOUR_APP_ID

This doesn't work for me. I still get the error saying the redirect_uri isn't owned by the user.

I would rather not have to add a page on my site to redirect them back to the site but its seems the correct way does not work.

The easiest fix i have found at the moment is to set the redirect_uri back to a page on my domain. The same domain as the page_tab content is loaded from.

e.g. My page tab loads hxxp://example.com/ so set the redirect_uri to hxxp://example.com/redirect.php

in redirect.php use the follow code

 <script>
window.top.location = "{YOUR_FACEBOOK_PAGE_TAB_URL}";
</script>
1
votes

I recommend using the FB.login() function if you want the user to remain on your Page Tab App after authorization. You can do so with this code:

FB.login(function(response) {
    if (response.authResponse) {
        // do something with newly authorized user
    } else {
        console.log('User cancelled login or did not fully authorize.');
    }
 }, {scope:'PERMISSION_1', 'PERMISSION_2'});

It will open the dialog in an iframe, and trigger the callback after they have submitted or cancelled the authorization.

This solution is using the javascript SDK.

0
votes

I think this might be because you are trying to redirect them back to facebook.com, so it doesn't see this as valid url for your application. You would need to redirect to a page on your own site, and then if need be redirect them from there back to the actual facebook page app tab