查看Twitter Web Intents API Documentation,在頁面底部附近,您可以找到未混淆的源代碼鏈接,其中顯示了它們的API如何自動處理鏈接。
簡而言之,他們將一個Click事件處理程序附加到DOM,然後檢查點擊鏈接是否指向他們的Web Intents URL。當您從ActionScript打開一個窗口時,您正繞過DOM,因此代碼不會觸發。
現在通常您只希望使用ExternalInterface來調用Web Intents API公開的方法;然而,Twitter上的聰明聊天室爲了避免污染DOM而創建了他們的整個API--要得到愛情;)
所以,我個人會通過創建我自己的Twitter Web Intents API版本來解決這個問題,包括它在我的Flash應用程序所在的HTML頁面上;例如:
// Create a global object which we can attach methods to.
var TwitterAPI = {};
// The methods themselves are created in a closure to avoid polluting the global
// namespace with temporary variables.
(function() {
// The base URL of the Twitter API.
TwitterAPI.baseURL = "https://twitter.com/intent/";
// Opens a pop-up window and prompts the user to retweet the Tweet linked to
// the supplied tweet_id.
TwitterAPI.retweet = function(tweet_id) {
var url = TwitterAPI.baseURL + "retweet?tweet_id=" + tweet_id;
openWindow(url);
}
function openWindow(url) {
var windowOptions = "scrollbars=yes,resizable=yes,toolbar=no,location=yes";
var width = 550;
var height = 420;
// Center the popup window.
var left = Math.round((screen.width/2) - (width/2));
var top = 0;
if (screen.height > height) {
top = Math.round((screen.height/2) - (height/2));
}
window.open(url, 'intent', windowOptions + ",width=" + width +
",height=" + height + ",left=" + left + ",top=" + top);
}
}());
然後,您可以從您的ActionScript項目通過ExternalInterface調用調用這個,因爲你曾建議:
ExternalInterface.call("TwitterAPI.retweet", "35782000644194304");
我當然不希望我不得不這樣做,但我認爲你是對的。還通過電子郵件在Twitter上聯繫了聯繫人,看看他們是否對此有任何意見。非常感謝您的幫助! –
我很抱歉跳到這個問題的線程。該例程運行良好,但我無法弄清楚的是如何在推文發佈後觸發Twitter的回調事件。通常,以下設置回調:twttr.events.bind('retweet',function(event){alert('retweet posted');});如何將它與您發佈的TwitterAPI一起使用?謝謝! – Victor