0

首先,嗨和感謝任何人誰可以提供幫助,因爲我已經瘋了這個幾個星期了。Facebook共享的意外行爲

所以我有一個網站列出了從我的移動應用程序中獲取的gif(然後存儲在AWS和我的訪問者(我沒有找到一個用於我的用戶)可以在Facebook上使用這些gif 。當我嘗試共享的圖像首次facebook的SDK

這個問題似乎

這就是共享對話框顯示第一次我點擊我的分享按鈕:

http://i.stack.imgur.com/lNVNF.png

然後我關閉,reclick相同的按鈕,現在它的工作原理:

http://i.stack.imgur.com/YsDUm.png

現在,我一直試圖找到一種方法,使第一個共享的嘗試,但都無濟於事這項工作。

我正在使用流星與biasport:facebook-sdk和Amazon S3共同託管我的文件。這裏

編輯是使用的代碼:

正面

HTML

<div class="facebook share"> 
    <img src="/gallery/fb.png"> 
</div> 

的Javascript

Template.*templateName*.events({ 
    'click .facebook': function(e){ 
     e.preventDefault(); 
     e.stopPropagation(); 
     // this is in a modal so I store the data I need 
     // (events have photos which in turn contain a url to the gif 
     var url = Session.get('event').photos[Session.get("id")].url; 
     FB.ui({ 
      method: 'share', 
      href: url 
     }); 
} 

服務器端

JAVASCRIPT

if(Meteor.isClient) { 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId  : 'APP_ID', 
      status  : true, 
      xfbml  : true, 
      version : 'v2.5' 
     }); 
    }; 
} 

編輯:我發現使用EXEC未來和捲曲

所以首先我加了一個電話到共享流星方法來更新Facebook的履帶

JAVASCRIPT

Template.*templateName*.events({ 
    'click .facebook': function(e){ 
     e.preventDefault(); 
     e.stopPropagation(); 
     // this is in a modal so I store the data I need 
     // (events have photos which in turn contain a url to the gif 
     var url = Session.get('event').photos[Session.get("id")].url; 
     Meteor.call('updateCrawler', url, function(){ 
      FB.ui({ 
       method: 'share', 
       href: url 
      }); 
     }); 
} 
手動解決方案

然後,我定義了我的流星法,就像這樣

JAVASCRIP牛逼

Meteor.methods({ 
    updateCrawler: function(url){ 
     var future = new Future(); 
     cmd = 'curl -X POST -F "id=' + url + '" -F "scrape=true" -F "access_token={my_access_token}" "https://graph.facebook.com"'; 
     exec(cmd, function(error){ 
      if (error){ 
       console.log(error); 
      } 
      future.return(); 
     }); 
     future.wait(); 
    } 
}); 

它是醜陋的,但因爲我不得不等待履帶更新和它的作品在這裏我要離開這個以備將來使用的人也許

EDIT2:

我做根本不使用og標記,因爲我只是直接共享一個url到aws而不是一個url到我的網站

+0

@Kyll我已添加相關代碼 –

回答

0

我通過從服務器直接調用Facebook API來解決這個問題,使它通過請求信息在頁面上。第一次它沒有緩存圖像,但第二次它做了這個解決方法之前共享初始呼叫。

爲您的Facebook應用程序使用訪問令牌,並在ajax調用中調用下面的內容,並在打開共享對話框之前等待響應。用自己的URI編碼地址https://graph.facebook.com/v2.5/?id=http%3A%2F%2Fwww.google.co.uk&access_token=xxxxx

編輯替換谷歌地址:

按照意見,這裏是調用這個我的服務器端方法,我用時的職位等插入進行初始呼叫,並提示從FB一刮:

var getTheOGInfo = function (link) 
{ 
    if (!link || link.slice(0, 4).toLowerCase() != "http"){ 
    throw new Meteor.Error("og-info-bad-url", "Function requires an unencoded fully qualified url"); 
    return false; 
    } 
    var url = "https://graph.facebook.com/v2.5/{{{{id}}}}?access_token={{{{token}}}}&fields=og_object{id,description,title,type,updated_time,url,image},id,share"; 
    var token = Meteor.settings.private.fb.token; 
    if (!token){ 
    throw new Meteor.Error("og-info-no-token", "Function requires a facebook token in Meteor.settings.private.fb.token"); 
    return false; 
    } 
    var link_id = encodeURIComponent(link); 
    url = url.replace('{{{{token}}}}', token).replace('{{{{id}}}}', link_id); 
    var result = HTTP.get(url, {timeout:1000}); 
    return result; 
} 

或者你的目的可能不希望任何可能會阻止這樣你就可以改變的最後兩行是aynchronous:

var result = HTTP.get(url, {timeout:1000}); 
return result; 

//Replace with non blocking 
HTTP.get(url, {timeout:1000}, function(err, result){console.log('something asynchronous', err, result);}); 
return true; 
+0

謝謝!去嘗試它給你一個更新儘快 –

+0

我試着這個使用post請求,但它似乎失敗(服務器端)與錯誤:失敗[500] {「錯誤」:{「消息」:「發生未知的錯誤。「,」type「:」OAuthException「,」code「:1,」fbtrace_id「:」BT9l3M8VSA0「}}]你可以發佈你的ajax請求嗎? –

+0

可以,但直到以後,當我在筆記本電腦時,您是否將xxxxx替換爲有效的通話令牌? Possubly嘗試直接在瀏覽器中,直到你有它的工作,然後在ajax出它...我昨天晚上寫了這個,所以才意識到你不需要每次有人分享它時調用這個是足夠的,服務器時,最初創建url/post –