简体   繁体   中英

Facebook API Error 100 - invalid link

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM