最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Facebook API Error 100 - invalid link - Stack Overflow

programmeradmin0浏览0评论

I am using the Facebook API to create a Send Dialog in my Rails App. I just use the format that Facebook remends 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: '',
          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 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: '',
      link: '',
      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)

I am using the Facebook API to create a Send Dialog in my Rails App. I just use the format that Facebook remends 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. 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.',
      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)

Share Improve this question edited Apr 5, 2013 at 20:33 Laurent asked Apr 5, 2013 at 9:15 LaurentLaurent 1,58419 silver badges42 bronze badges 7
  • What’s the actual JS code that the client receives? – C3roe Commented Apr 5, 2013 at 9:32
  • @CBroe just elaborated on the code that calls the function. Anything more I can bring, please say. – Laurent Commented Apr 5, 2013 at 10:03
  • Please show the code that the client receives, after your ruby code is executed on the server. – C3roe Commented Apr 5, 2013 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 Commented Apr 5, 2013 at 10:30
  • 1 An image URL of "fb-logo-75.png" is not valid, btw. Not sure if thats causing the issue or what, but it's invalid nevertheless. – Tommy Crush Commented Apr 5, 2013 at 20:39
 |  Show 2 more ments

1 Answer 1

Reset to default 4

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

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

发布评论

评论列表(0)

  1. 暂无评论