11

This has been working fine for over a week.

FB.ui({
  method: 'send',
  to: connectionid,
  name: subject,
  picture: staticurl + 'images/logoformysite.png',
  link: homeurl + '/' + username + '/something=' + var1 +'&somethingelse=' + encodeURI(var2) + '&evenmore=' + encodeURI(var3),
  description: invitemessage,
});

I had initially had an error last week where if the URL was within the Facebook domain, Facebook would block it. I fixed that and now both the picture and the link do not belong to the Facebook domain and come from my site. But this started happening today with nothing changed. It is intermittent.

An error occurred. Please try again later.

API Error Code: 100 API Error Description: Invalid parameter Error Message: 'link' is invalid.

It is not clear why it works sometimes and not other times even if I am sending it to the same user. Wondering if I missed an announcement. But I would hope that it would at least fail consistently but that is not the case.


UPDATE: I am not sure how the link I am setting in the dialog can be set globally on the page. It will send the recipients of the message the wrong link. It would be really helpful to see an example of how the above would work in the new open graph world.

ANSWER AUG 12 2013

The issue revolved around our url being dynamic and needing force caching each time. I now make an ajax call to "https://developers.facebook.com/tools/debug/og/object" to refresh it and then launch the send dialog.

k c
  • 211
  • 1
  • 2
  • 15
  • Safe to assume you're confident that `homeurl + '/' + username + '/something=' + var1 +'&somethingelse=' + encodeURI(var2) + '&evenmore=' + encodeURI(var3)` is always creating the same (valid) url string? You may want to extract that into a variable and `console.log()` it out before the `fb.ui()` call just as a sanity check – Zach Lysobey Jul 31 '13 at 22:39
  • I have double checked that in the chrome console and it is the full url. https://mydomain.... – k c Jul 31 '13 at 22:43
  • I'm consistently facing this issue from the last 2 days – rdsoze Aug 01 '13 at 18:20
  • Yes - same here. We have had no luck so far. – k c Aug 01 '13 at 22:30
  • check my answer for this question http://stackoverflow.com/questions/7539659/avoiding-error-100-invalid-parameter-requires-valid-redirect-uri-in-applicati/34068735#34068735 – Shady Mohamed Sherif Dec 03 '15 at 14:37

3 Answers3

9

I had the same issue and that stopped working since last week.

Here is my solution:

Go to Facebook debugger and add your URL. Click on "Debug" and fix all warnings displayed by Facebook.

To fix mine I had to add the og.url meta tag in my page. The value should be exactly the same as the one you want to share (no redirection). Then Facebook sent me this notification (alert):

Your app, XXX, is now compliant with the Stream post URL security migration. No further action is required.

Try to share your link with FB.ui once again and now your post should automatically display your og values.

Note: Facebook October breaking change will automatically use those og metas instead of custom FB.ui parameters, therefore you can now activate the breaking change to get ready and remove name/picture/description from your code.

UPDATE: This problem can happens again even if what I mentioned above is correctly implemented.

If it is your case that's because you have to enforce Facebook to "scrape" your page. This process is automatically done by Facebook when you use the Facebook object debugger or you copy/paste your link on your timeline / private messages. If you use the JavaScript SDK you have to ask Facebook to index and cache your page.

You won't find this in the Facebook documentation related to the JavaScript SDK (or you are lucky) so to save you all the days I lost to find this unbelievable issue (remember Facebook only said your link is invalid) you can find more details on this page.

I tried to use the Graph API to enforce my newly created page to be scraped by Facebook, if it works for you you are lucky. The second method which is not mentionned but produced the same result is to send a request to the Facebook Object Debugger page and add your page link in the URL (e.g. https://developers.facebook.com/tools/debug/og/object?q=YourPageUrlHere). By doing this Facebook will this time scrape your page and now you can share your links with the Facebook API, everything is now working.

glautrou
  • 3,140
  • 2
  • 29
  • 34
  • Interesting...but the url I share using the dialog is customized with some query string parameters. The sendDialog is launched by multiple anchors with dynamic values. Will this be no longer supported? I could not just put one og.url in the page tag because it won't work. – k c Aug 06 '13 at 17:54
  • I thought the migration is happening in October but seems like it is already breaking us. I have added a new question to address this here. http://stackoverflow.com/questions/18088472/migrating-facebook-send-dialog-parameters-to-opengraph-changes – k c Aug 06 '13 at 19:09
  • I fixed all the warnings by adding the og tags to the pages. Now the facebook debugger is happy. Using the send Dialog works fine for my account (I was able to send messages) but it still fails for other members in my team with the same link is invalid error. – k c Aug 06 '13 at 22:16
  • @kc: I have updated my answer, everything works fine on live for all my websites and my clients are happy with this. Please accept the answer if your problem is fixed. – glautrou Aug 09 '13 at 16:18
  • Hi - my problem is not fixed. The link is fine in the facebook debugger. No complaints. I still get the link is invalid intermittently using the send Dialog though. Sometimes to the same person even. – k c Aug 12 '13 at 14:23
  • If everything is fine in the Facebook debugger check at your page on which you use the JavaScript SDK. Do you have any error in the JavaScript console? Do you force your link to be scraped as I added in my updated answer? – glautrou Aug 12 '13 at 14:27
  • I have force scraped the page with the debugger. There is no javascript error. There are 2 issues: (1) the link query string parameters can change and (2) I do not have permissions to see the page as the sender --- wondering if facebook is trying to access the page as me on the client side. – k c Aug 12 '13 at 15:22
  • (1) Can you confirm that the link you pass to `FB.ui()` doesn't expire. (2) Facebook can only access to public pages (i.e. crawlable by search engine). Can you access to your page to be shared without the need to log-in or something else? – glautrou Aug 12 '13 at 15:40
  • It does not expire. It is completely accessible without requiring any login. I think I have identified the issue. It is with the changing url. The problem is that my link can change based on the user and the vars: homeurl + '/' + username + '/something=' + var1 +'&somethingelse=' + encodeURI(var2) + '&evenmore=' + encodeURI(var3). As soon as I scrape every url manually it is working. Perhaps I need something like this: http://stackoverflow.com/questions/12100574/is-there-an-api-to-force-facebook-to-scrape-a-page-again – k c Aug 12 '13 at 15:53
  • Cool :) Yes this is another method as explained in one of my links about Facebook objects scraping, but requires to use `curl`. Question: Why your URL for a same page can change? This is another subject but 1 page = 1 URL, that will simplify your code, better caching, better SEO... – glautrou Aug 12 '13 at 15:59
  • I have the same problem with Send method. What I have to give in Facebook debugger URL? Please advice me because I am not clear. – user2003356 Oct 12 '13 at 05:44
  • The Facebook Debugger URL should be the same as the URL provided to the Facebook API (your targeted page, for example your news article) – glautrou Oct 13 '13 at 10:58
5

I can confirm that this was fixed for me when I forced Facebook to first scrape the URL before trying to send that same URL via the FB UI Dialog.

Sample code:

FB.api('https://graph.facebook.com/', 'post', {
    id: '[URL]',
    scrape: true
}, function(response) {
    FB.ui({
        method: 'send',
        name: '[name]',
        picture: '[Picture URL]',
        link: [URL]',
        description: '[description]'
    });
});
Scott
  • 3,736
  • 2
  • 26
  • 44
  • 1
    Had this same problem, and this same solution still seems to be working. If the url you plan to have users share is unlikely to have been scraped before (especially if it's custom to the user, generated right then an there) this sort of call will prime the pump, as it were, making it much more likely that you're not going to get a 100 error when you share. – Dtipson Apr 30 '15 at 02:32
  • @Dtipson, does it still work with the new Graph API 2.0 that they released today? – Scott May 01 '15 at 02:54
  • @Scott, could you help plase heare https://stackoverflow.com/questions/66654709/facebook-sdk-send-method-in-reactjs – Asking Mar 17 '21 at 08:55
0

Make sure that when facebook requests your url, it will never be forwarded.

A way to do this is to present facebook with a special page of its own, containing all the right ingredients.

Here is an example (sort of based on php + symfony 1.4):

<?php
    if(preg_match('/facebookexternalhit/i', $request->getHttpHeader('User-Agent')))
    { ?>
        <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
        <meta property="fb:app_id" content="<?php echo sfConfig::get('app_facebook_app_id'); ?>" />
        <meta property="og:url" content="<?php echo sfContext::getInstance()->getRequest()->getUri(); ?>" />
        <meta property="og:title" content="<?php echo $title; ?>" />
        <meta property="og:description" content="<?php echo $description; ?>" />
        <meta property="og:image" content="<?php echo $image; ?>" />
      </head>
      <body>
        hello Facebook!
      </body>
    </html>
    <?php
    }
?>
Esoteric Screen Name
  • 6,082
  • 4
  • 29
  • 38
hexiecode
  • 91
  • 1
  • 1
  • We don't have any url forwarding going on. The url passed to send Dialog is the url that shows when the page is rendered. – k c Aug 06 '13 at 22:17
  • 1
    @hexiecode: You shouldn't code like this anyway, `og` are not only used by Facebook, for others like Twitter it is better not to have redirections as well. If Facebook user-agent changes or he wants to implement Twitter he will have to maintain this code and it will be more complex. If you look at News Websites you can see in the source code that `og` + `fb` + `twitter` metas are generated. – glautrou Aug 07 '13 at 08:15