簡體   English   中英

Facebook API錯誤100-無效鏈接

[英]Facebook API Error 100 - invalid link

我正在使用Facebook API在Rails應用程序中創建“發送”對話框。 我只是使用Facebook在Javascript中推薦的格式(作為HTML中的腳本)。

我的問題是我得到了:

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

在以下內容上:

 <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>

請注意:

a)Facebook :: SITE_URL隨環境而變化。 您可能會認為這是本地主機問題。 但是,當我整合網站URL的值(這是一個有效的網站,與localhost不同)時,仍然會出現錯誤。 但是,該鏈接(到我在Heroku上的應用程序)肯定有效。

b)無論是從本地主機還是在生產環境中發布供稿時,都不會出現錯誤。 該問題似乎僅限於“發送”對話框。

c)當我輸入另一個URL(例如http://www.cnn.com )時,沒有收到錯誤消息。 這是在頁面上調用該方法的方式:

    <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>

注意:User.gender_article是一種黑客程序,如果用戶是男性,則提供“他/他/他”;如果用戶是女性,則提供“他/她/她”。

這就是在客戶端翻譯的方式:

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>

這是腳本在客戶端上的樣子:

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.'
      });
}

請注意,此鏈接實際上是功能性鏈接(盡管存在許多錯誤-但它存在並且鏈接到實際網站)

http://fb-logo-75.png的圖片網址無效

它必須是絕對網址(例如: http : //domain.com/path/to/image.png ),並且不能位於Facebook的CDN上。 因此,將其更改為http://your_domain.com/path/to/fb-logo-75.png

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM