1

I'm using FB.ui() like so:

<script>
      window.fbAsyncInit = function() {
        FB.init({
          appId      : '##########', // App ID
          channelUrl : '//www.xxxxxxxxxx.com/channel.php', // Channel File
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true  // parse XFBML
        });
    
        // Additional initialization code here
      };
    
      // Load the SDK Asynchronously
      (function(d){
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/en_US/all.js";
         ref.parentNode.insertBefore(js, ref);
       }(document));
    </script>

Then, here's the link to send the message:

<a href='#' onClick="
        FB.ui({
          method: 'send',
          name: 'Bla bla bla',
          link: 'http://www.xxxxxxxxxxx.com',
          to: ###########,
          //redirect_uri: 'http://www.xxxxxxxxxxx.com/fb/'
          });
        ">Send a message</a>

PROBLEM: This works like a charm for me and every computer/browser I've tested on. But my client gets the following error message very frequently:

API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application

enter image description here

This has me totally stumped! Is anything wrong with my code? And if so, why can't I EVER reproduce this bug while my client consistently can on multiple computers/browsers?

PS: If you want to try yourself, the page is live here. You'll have to authorize the app, but I promise nothing creepy will happen.

EDIT: The error mentions the redirect_uri, which you'll notice is commented out in my code. The reason is because when I include that parameter, the dialogue doesn't close when I hit "close".

EDIT2: I was able to reproduce this bug on a friend's computer, and CBroe also confirmed it. So, (setting aside the mystery of why I still can't produce it myself), the thing that has me most stumped is why does this only happen half of the time?? If my code is incorrect it should never work, right??

Here's the url from the error message:

https://www.facebook.com/dialog/send?display=popup&link=http%3A%2F%2Fwww.streetofwalls.com&locale=en_US&name=Career%20Networking%20powered%20by%20Street%20of%20Walls&next=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D8%23cb%3Df2c657ef78%26origin%3Dhttp%253A%252F%252Fwww.streetofwalls.com%252Ff3575a615c%26domain%3Dwww.streetofwalls.com%26relation%3Dopener%26frame%3Df1ca46b43c%26result%3D%2522xxRESULTTOKENxx%2522&sdk=joey&show_error=true&to=573501273 

After url_decode() version:

https://www.facebook.com/dialog/send?display=popup&link=http://www.streetofwalls.com&locale=en_US&name=Career Networking powered by Street of Walls&next=http://static.ak.facebook.com/connect/xd_arbiter.php?version=8#cb=f2c657ef78&origin=http%3A%2F%2Fwww.streetofwalls.com%2Ff3575a615c&domain=www.streetofwalls.com&relation=opener&frame=f1ca46b43c&result=%22xxRESULTTOKENxx%22&sdk=joey&show_error=true&to=573501273

EDIT3: Part of this puzzle is solved. The times when the error occurs are the result of FB.init() not working. I've wrapped the FB.ui() in FB.getLoginStatus(function(response){ \\... } so now you can see a more useful error in the console. The open question is... WHY DOES FB.init() fail so often?

Community
  • 1
  • 1
emersonthis
  • 32,822
  • 59
  • 210
  • 375
  • I can confirm the error when I click on “Expand your network by inviting Friends to connect” on the start page after allowing your app. (I only get the error message in red border, not the detailed error codes, but that’s because it not in debugging mode for me I guess.) – CBroe Jun 29 '12 at 07:36
  • This is SO confusing. The error message seems to vary, and I can't reproduce it at all! I added a `show_errors: true` parameter before posting the question, which seems to display the additional info... sometimes. – emersonthis Jun 29 '12 at 12:17
  • @CBroe: is the error intermittent for you as well? My client says it only appears every second or third page reload. – emersonthis Jun 29 '12 at 12:20
  • Looks like you‘ve switched from displaying the dialog as a popup to an inline dialog now? Now I’m not getting the error any more. – CBroe Jun 29 '12 at 13:43
  • I read somewhere that overtly specifying `display:'popup'` might fix things, but it didn't work for me. The popup was glitchy and wouldn't close when I hit cancel, or reverted it. Are you not getting the error at all? Or is it just not showing the message? It should happen every few page loads. 5 tops. – emersonthis Jun 29 '12 at 15:12
  • Nope, can’t reproduce it any more. – CBroe Jun 29 '12 at 15:33
  • I thought things couldn't get weirder... and then they just did. My client claims to still be getting the error, but my impression is that the frequency has dropped. Ugh! – emersonthis Jun 29 '12 at 20:17
  • What's the site url in your app settings? – borisdiakur Jul 02 '12 at 13:20
  • 1
    I'm not exactly sure what's going on, I was trying your site and got "an error occurred" in the popup. Then I found out that `FB.init` was not even called, so i called that, and after that it worked. – Nitzan Tomer Jul 02 '12 at 14:26
  • Huh. So this would suggest that `FB.init` is sometimes not getting called... which would explain why the `FB.ui()` wouldn't work. I can't think of why this would happen because `FB.init` it's coded into the template. I wonder if there's some other script that might conflict with it (but SOMEtimes???). – emersonthis Jul 03 '12 at 14:02
  • check I think this is the issue here http://stackoverflow.com/a/11212311/384554 – PUG Nov 08 '12 at 01:52

3 Answers3

0

This is due to a configuration error between your redirect_uri and the settings that you have specified for your Facebook app. See the answer to this question.

The redirect_uri should be equal (or relative) to the Site URL that you set in your Facebook app's settings. So make sure your Site URL is set and that it points to a directory that is equal to or lower than your redirect_uri. Also, make sure you have set the app's domain correct in Facebook's settings.

For example:

App domain: streetofwalls.com

Site URL: / Secure Canvas URL: / Secure Page Tab URL: http://www.streetofwalls.com

Community
  • 1
  • 1
Michael Frederick
  • 16,664
  • 3
  • 43
  • 58
  • 1
    It's not this. I've seen that mistake made all over the place, and I've tried every plausible domain in the app settings (with trailing backslash, without trailing backslash, etc). In fact, if you look at my code you'll see that I'm not even declaring a redirect URL at all (see comment to CBroe above). And it works 2/3 of the time. So how could this be the problem? The little I know about FB API stuff has taught me that incorrect settings cause things to just STOP working entirely as opposed to working sometimes. – emersonthis Jul 03 '12 at 14:07
0

First you load the following script in the head of your page:

<script type="text/javascript" src="http://www.streetofwalls.com/wp-content/themes/streetofwalls/js/main.js"></script>

Inside that script you try to load the FB JavaScript SDK asynchronously. The SDK requires the fb-root element in order to load properly as stated in the docs. But your fb-root element might not be rendered yet, so here is the problem I guess.

Put the window.fbAsyncInit = ... and the code for loading the SDK asynchronously inside jQuery(document).ready(function($) { ... }); and you should be fine.

For debugging you could also try to load the Facebook SDK synchronously.

Another thing I have noticed: You have two script tags inside the head of your site which load the FB JavaScript SDK. You should remove both.

borisdiakur
  • 10,387
  • 7
  • 68
  • 100
  • This makes sense, but I tried it and when I did I got the error every singel time. So I moved it back out of the `$...ready()` – emersonthis Jul 03 '12 at 22:42
  • by the way, I couldn't find the two scripts loading the SDK. Can you tell me where/how you see that? – emersonthis Jul 03 '12 at 22:57
  • Well, now I can find only one script, loading the SDK. View source, then search for "all.js". – borisdiakur Jul 04 '12 at 07:46
  • 1
    You can also try to keep your javascript as it is and just move the according script tag where you load the FB SDK asynchronously below `fb-root`. – borisdiakur Jul 05 '12 at 11:19
-1

So Nitzan deserves the credit for this for his insightful comment, but here's the solution.

The error message I was getting was a result of the fact that FB.init() wasn't loading, or at least it wasn't loading in the proper order with respect to the rest of the page. I copied the code from the Facebook Developer docs and it loads asynchronously... which turns out to be kind of a big pain in the ass...

So instead of what I had, I switched to loading it the old fashioned way:

FB.init({
      appId      : '##########', // App ID
      channelUrl : '//www.xxxxxxxxxx.com/channel.php', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

This, combined with some reordering of the other scripts, seems to have resolved my problem.

emersonthis
  • 32,822
  • 59
  • 210
  • 375
  • As I mentioned in my answer, you can load the JavaScript SDK synchronously for debugging. But remember that this method is not recommended for typical use as stated in the [docs](https://developers.facebook.com/docs/reference/javascript/). Synchronous operations will block the web page, resulting in worse performance and a slower user experience. This may also negatively impact SEO due to the increased slowness perceived by robots and crawlers. – borisdiakur Jul 04 '12 at 07:52
  • Is loading this script synchronously any worse than loading any other stript synchronously? I get why asynchronous is advantageous, but my problem is that it doesn't work (At least not for me)! And after troubleshooting this for weeks, it seems like a LOT of people have this problem, and Facebook doesn't make it any easier to solve by not providing a simple callback function to tell you when the SDK is initialized. – emersonthis Jul 05 '12 at 10:55
  • The setup for asynchronously loading the SDK is pretty much prone to error, as you have already noticed, but my experience is, that there is always a way to do it right. You just have to tweak your code and experiment a little. I have added another comment below my answer on what else you could try. Good luck! – borisdiakur Jul 05 '12 at 11:50