-3

I'm trying to use Facebook's JavaScript SDK to let users send a link to another user, i.e using FB.ui(data, callback). console.log( data ) gives this output:

link
    "http://example.com/something/y3k62pg3t4"

method
    "send"

to
    "10000xxxxx(omitted)"

The issue is, this is able to display the facebook send dialog correctly (i.e the dialog opens, friend's name is pre-filled, link is selected showing the correct url, thumbnail, etc). However when I click send, the callback function is never called, and the friend also never receives the PM.

However if I change the url to google.com, then both things work, i.e callback is called and PM also gets sent.

Any ideas on what's wrong?

Edit:

This is what I've found. If I have a Facebook app linked to a domain e.g example.com, then from that app I can send links to any site EXCEPT example.com. So it seems like an anti-spam measure put in place by Facebook.

Can someone confirm that they're able to send links from the same domain name that their app is linked to, or if they also experience this issue?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Ali
  • 261,656
  • 265
  • 575
  • 769
  • 2
    Your theory about why it's happening doesn't quite make sense, there are options on an app's settings to prevent it posting to URLs OTHER than those it owns, but not to prevent apps posting links to themselves :/ – Igy Jul 09 '12 at 18:08
  • 5
    Can you update the question with a complete html/js page that reproduces your problem? I have a feeling you will only get guesses as answers in the absence of code. Nobody else seems to be having the same problem as you, and this is not an obscure bit of the Facebook API, which usually means you are doing something unconventional in your code. – Pat James Jul 11 '12 at 15:14
  • If you have set up an app and initialized FB with your app id, please check if you have inserted a Site URL in your app settings. – borisdiakur Jul 10 '12 at 07:58
  • Is the URL you’re trying to send publicly reachable over the internet? Facebook tries to fetch the URL and have a look at it before you post it. – CBroe Jul 06 '12 at 20:09
  • yeah it definitely is, its able to get the title & thumbnail of that picture – Ali Jul 06 '12 at 20:09
  • how are you supposed to develop this functionality with a dev site then...? – sevenseacat Jul 09 '12 at 08:25
  • @Karpie what do you mean? I don't have the functionality, that's the issue – Ali Jul 09 '12 at 13:28

5 Answers5

1

Bit of a long shot but have you tried putting the link through the Facebook Debug tool, to see what it will see when it scrapes the file's meta data? It might show up an error.

Also I've had trouble using links that were pointing to my own internal server, where i had a dynamic DNS in use (in my case from no-ip.com). So that's perhaps something else to cross off the list.

Good luck.

-- EDIT --

Here's the JS code I used to create the send request:

var obj = {
        method: 'send',
        to: '<test user ID>',
        name: 'My Title',
        caption: 'My Caption',
        description: 'My Message',
      link: 'http://apps.facebook.com/<app name>/',
      picture: 'http://<no-ip domain>/images/testpos.jpg'
    };

FB.ui(obj, callback);
Snouto
  • 1,039
  • 1
  • 7
  • 21
  • Thanks, I just tried it, and I get a bunch of warnings about `og:title`, `og:image` etc but I get the same warnings for google.com, so I don't think that's it. However are you able to send links right now in your app? – Ali Jul 09 '12 at 14:19
  • I just gave the Send UI dialog a shot and it worked. I used it between two test users and although I saw the Captcha twice(?) the post was made after I put the captcha text in the first time. This was through use of a link pointing to my app's facebook url (e.g apps.facebook.com/...) and an image on my local webserver. I've put the code in my original answer for better formatting – Snouto Jul 09 '12 at 14:32
  • good one, any chance if you could try changing the link to some other website other than facebook or google? because google.com works for me and my own website doesn't. can you try it with a personal website and a non-test user? (you don't have to share the url here) – Ali Jul 09 '12 at 15:04
  • Yeah that worked too. I linked to **http://www.nufc.com** and used a picture URL from a random google search, and sent it to my gf using her ID in the request. Worked fine. You are running FB.init with a correct/valid app ID right? [link](https://dl.dropbox.com/u/7810832/Test%20Send%20Message.jpg) – Snouto Jul 09 '12 at 15:16
  • It's Facebook dude, if it doesn't do your bulb in at some point or other you aren't doing something right! Bit of a long shot but have you tried putting your HTML & JS on a different server and running it from there? Ever since FB flat refused to accept a perfectly accessible picture URL I once tested with, i've been very wary of URLs and domains i've used in my tests. I probs can't be of much more help without seeing the code you're trying to use but keep updating this thread and if I can help further I'll chip in. Good luck! – Snouto Jul 09 '12 at 16:45
  • It sounds more and more like there's something FB doesn't like about the URL you're trying to share. Shot in teh dark - it hasn't got any infinite 302 redirections going on or anything like that? – Snouto Jul 09 '12 at 16:55
  • Ok so this is the deal, I've got 2 copies of the site, one running on my localhost with an app whose domain is set to localhost, and one running on example.com whose domain is example.com. If I try to send a link to any site from example.com, it works, but links from example.com don't work. Similarly on localhost, all links INCLUDING example.com work, however localhost links don't work. So it seems like all links EXCEPT the one from the domain linked to your facebook app work. – Ali Jul 09 '12 at 16:56
  • Do you have any apps linked to a particular domain from where you're able to send links on the same domain that your app is linked to? – Ali Jul 09 '12 at 16:57
  • I just tried the Send action again, this time with the link being of the same domain as where my app is connected to (and where my test page is running from). This would be the no-ip.com domain I use for dev work, and again it worked fine. Are both your site copies running from the same machine? – Snouto Jul 09 '12 at 17:06
  • No, example.com is being hosted on a web host. – Ali Jul 09 '12 at 17:07
  • I'm out of ideas mate, sorry. Without being able to see or try your code I'm pretty much plucking things out of the air now :/ – Snouto Jul 09 '12 at 17:09
  • This is my code for fb.init, anything fishy in there? `window.fbAsyncInit = function() { FB.init({ appId : 'xxx', channelUrl : 'http://localhost/xxx/channel.php', status : true, cookie : true, frictionlessRequests : true }); FB.Event.subscribe('auth.statusChange', updateStatus); };` – Ali Jul 09 '12 at 17:10
  • Also are you sure that the app you used has got the same domain listed in both the 'app domain' and 'site url' settings? P.S thanks for your help so far :) – Ali Jul 09 '12 at 17:14
  • Your code is a little different to mine, not sure it's "fishy" per se but maybe try removing the frictionless setting (think this only applies to Requests), add in "xfbml:true", and ensure your channelURL PHP file is set up as per [this blog post](https://developers.facebook.com/blog/post/530/). As for the app domain and site url - yes. they're both set to point to the same domain. Actually, thanks to a bug, I can't see the app domain list in the FB settings but I know for a fact it's using the same domain because I entered it again a few days ago. – Snouto Jul 09 '12 at 17:24
1

Try these two options

a. Manually invoke the send url

https://www.facebook.com/dialog/send?app_id=YOUR_APP_ID&name=TITLE_OF_POST&link=LINK_FOR_DOMAIN&redirect_uri=LINK_FOR_DOMAIN

Address the to field to yourself to cut out your friend.

If successful you should hit the redirect uri and see the message in your inbox if not, you should see an error.

b. Catch the response

var data = {
      method: 'send',
      to: 'YOUR_ID',
      name: 'My Title',
      link: 'YOUR_DOMAIN',
    };

function requestCallback (response) {
    console.log(response);
}

FB.ui(data, requestCallback);

If successful you should get an empty array and see the message in your inbox. If not, you should get the error message returned in an object.

Between these two options, you should be able to pinpoint what is not set correctly in your application.

phwd
  • 19,975
  • 5
  • 50
  • 78
0

It looks that there might be a Facebook BUG . Using my application I'm getting a

POST https://www.facebook.com/dialog/send 500 (Internal Server Error)

Here are bugs that you can subscribe on this issue : https://developers.facebook.com/bugs/426059697438651 https://developers.facebook.com/bugs/379191648801449

valentinvieriu
  • 547
  • 5
  • 9
0

There are some domains that are blocked. I know that all .TK-domains (just try sending http://dot.tk to a friend) for example (I have already had the issue myself) are marked as spam and whenever you try to send them within a message, the message is - as in your case, using the send dialog - rejected.

Facebook also follows Location-header-redirects, that's the problem, you cannot just use URL shorteners.

To avoid being marked as spam you could make use of page cloaking. The only thing you need for redirection is one whitelisted domain which you can place the following script on.

<?php
$UserAgent=$_SERVER['HTTP_USER_AGENT']; //The user agent header
$URL=$_GET["URL"]; //The URL to be redirected to
if(preg_match("#(^facebookexternalhit/|\\(\\+http://(www\\.|[a-zA-Z0-9-]{1,}\\.)?facebook\\.com($|/))#i", $UserAgent)) //Is it a facebook agent?
{
    //Deliver content prepared for facebook
    echo '<html>
    <head>
        <meta name="og:image" content="http://example.com/logo.png" />
        <meta name="og:title" content="Page title for facebook" />
        <meta name="og:description" content="Any description of your page." />
        <meta name="og:url" content="http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'" />
    </head>
    <body>
    </body>
    </html>';
    exit();
}
else
{
    //This is not a facebook agent, redirect client to $URL
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: ".$URL);
    exit();
}
?>

Another possibility would be a JavaScript redirection, but this would not work for all users.

EDIT: I have used your code and it works fine for a whitelisted page.

1' OR 1 --
  • 1,694
  • 1
  • 16
  • 32
0

I had similar issues when trying to refer to a FB App URL in an fb.ui send operation.

The cause was that FB was using an outdated copy of the webpage (with errors in it).

So make sure that FB uses the latest copy of your webpage if you are doing testing (and keep changing the content of the destination URL).

You can achieve this by passing your URL's once more through the FB Debugger at https://developers.facebook.com/tools/debug

Rolf
  • 398
  • 3
  • 9