2

I am using the Facebook API to create a Send Dialog in my Rails App. I just use the format that Facebook recommends in a Javascript (as a script in HTML).

My problem is that I get an:

 API Error code 100, invalid parameter, link URL not properly formatted

on the following:

 <script>

    function detail(friend_id, user_name, restaurant_name, restaurant_id, articles){
      // assume we are already logged in
      FB.init({appId: '<%= Facebook::APP_ID.to_s %>', xfbml: true, cookie: true});

      FB.ui({
        to: friend_id,
          method: 'send',
          name: user_name +' needs more details about '+ restaurant_name,
           picture: 'http://fb-logo-75.png',
          link: "<%= Facebook::SITE_URL%>restaurants/"+restaurant_id,
          description: '<b>'+user_name + ' needs your help.</b> Add some color to your review of <b>'+restaurant_name+'</b> and help '+articles["object"]+' decide if he should eat there.'
          });
    }
     </script>

Please note that:

a) The Facebook::SITE_URL changes depending on the environment. You may think this is a localhost problem. However when I integrate the value of the website URL (which is a valid website, unlike localhost) I still get an error. Yet that link (to my app on Heroku ) is definitely functioning.

b) When I post to feed, whether from localhost or in production, I don't get an error. The problem seems confined to the Send Dialog.

c) when I put in another URL such as http://www.cnn.com I don't get an error. Here is how the method is called on the page:

    <li class = "flat_list_item"><button id="detail_friend" onclick='detail(<%= review.user.fb_id.to_s %>, "<%= @current_user.first_name.to_s %>",
"<%= review.restaurant.name.to_s %>", <%= review.restaurant.id %>,<%= @current_user.gender_article.to_json %>)'>Tell me more</button></li>

NOTE: User.gender_article is a hack that provides "his/him/he if the user is male, "her/her/hers if the user is female.

This is how this translates on the client side:

The HTML:

<button id="detail_friend" onclick="detail(XXXX, &quot;Laurent&quot;,&quot;Refuge&quot;, 227,{&quot;subject&quot;:&quot;he&quot;,&quot;possess&quot;:&quot;his&quot;,&quot;object&quot;:&quot;him&quot;})">Tell me more</button>

And this is what the script looks like on the client side:

function detail(friend_id, user_name, restaurant_name, restaurant_id, articles){
  // assume we are already logged in
  FB.init({appId: 'XXXX', xfbml: true, cookie: true});

  FB.ui({
    to: friend_id,
      method: 'send',
      name: user_name +' needs more details about '+ restaurant_name,
       picture: 'http://fb-logo-75.png',
      link: 'http://powerful-woodland-3700.herokuapp.com',
      description: '<b>'+user_name + ' needs your help.</b> Add some color to your review of <b>'+restaurant_name+'</b> and help '+articles["object"]+' decide if he should eat there.'
      });
}

Note that this link actually is a functional link (albeit with a lot of bugs - but it exists and links to an actual website)

Laurent
  • 1,554
  • 19
  • 42
  • What’s the _actual_ JS code that the client receives? – CBroe Apr 05 '13 at 09:32
  • @CBroe just elaborated on the code that calls the function. Anything more I can bring, please say. – Laurent Apr 05 '13 at 10:03
  • Please show the code that the client receives, __after__ your ruby code is executed on the server. – CBroe Apr 05 '13 at 10:05
  • @CBroe I just have to be frank and admit I'm not 100% sure what you are asking - this entirley due to my lack of experience. I attached above the URL request that is formed by the code. I think I'm unclear about where to find the code the client receives - I'm embarassed to say. If you still have patience to clarify that, I'll find it. – Laurent Apr 05 '13 at 10:30
  • @CBroe I think I understood what you meant... hope you're still interested in helping out. See updated question – Laurent Apr 05 '13 at 20:34
  • 1
    An image URL of "http://fb-logo-75.png" is not valid, btw. Not sure if thats causing the issue or what, but it's invalid nevertheless. – Tommy Crush Apr 05 '13 at 20:39
  • Hey @TommyCrush that solved it! I should have figured that out on my own, I'm embarassed. Go ahead and put the comment up as an answer, I will definitely check it. Also can you explain briefly why it's not valid and what format would be? For some reason I have failed to attach an image to my send dialogs. – Laurent Apr 05 '13 at 20:42

1 Answers1

4

The image URL of http://fb-logo-75.png is not valid

It must be an absolute url (example: http://domain.com/path/to/image.png) and cannot be located on Facebook's CDN. So change that to http://your_domain.com/path/to/fb-logo-75.png

Tommy Crush
  • 2,790
  • 1
  • 15
  • 18