2013-04-05 77 views
2

我正在使用Facebook API在我的Rails應用程序中創建發送對話框。我只是使用Facebook推薦的Javascript格式(作爲HTML中的腳本)。Facebook API錯誤100 - 無效鏈接

我的問題是,我得到一個:以下

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> 

請注意:

一)根據對環境的Facebook的:: SITE_URL變化。您可能認爲這是本地主機問題。但是,當我整合網站URL(這是一個有效的網站,不像本地主機)的價值時,我仍然遇到錯誤。然而,這個鏈接(我Heroku 上的應用程序)肯定是正常運行。

b)當我發佈feed時,無論是從localhost還是生產中,我都沒有收到錯誤。這個問題似乎侷限於發送對話框。

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

注意這個鏈接實際上是一個功能鏈接(雖然有很多的錯誤 - 但它存在並鏈接到一個實際的網站)

+0

客戶端收到的_actual_ JS代碼是什麼? – CBroe 2013-04-05 09:32:11

+0

@CBroe剛剛闡述了調用函數的代碼。我可以帶來更多的東西,請說。 – Laurent 2013-04-05 10:03:11

+0

請顯示客戶端收到的代碼,__after__您的ruby代碼在服務器上執行。 – CBroe 2013-04-05 10:05:14

回答

相關問題