2012-05-30 154 views
1

我想分享從閃存AS3網站的URL,我不能讓它十分正常工作...... 我想在這裏給出的兩種方式:How to create a share button in AS3從AS3網站分享鏈接至Facebook

第一個作品:

import flash.net.navigateToURL; 
import flash.net.URLVariables; 
import flash.net.URLRequest; 
import flash.net.URLRequestMethod; 

share_btn.addEventListener(MouseEvent.CLICK, shareClickHandler); 

function shareClickHandler(evt:MouseEvent):void 
{ 
    var varsShare:URLVariables = new URLVariables(); 
    varsShare.u = 'http://domain.com/pageN.html'; 
    varsShare.t = 'Title Page'; 

    var urlFacebookShare:URLRequest = new URLRequest('http://www.facebook.com/sharer.php'); 
    urlFacebookShare.data = varsShare; 
    urlFacebookShare.method = URLRequestMethod.GET; 

    navigateToURL(urlFacebookShare, '_blank'); 
} 

但是,在帖子裏說:

In order to use a picture add the following Metatags: 
<meta name="title" content="my title" /> 
<meta name="description" content="my description" /> 
<link rel="image_src" href="images/thumbnail_image.jpg" /> 

但如何????

第二個解決方案演示如何添加參數:

var req:URLRequest = new URLRequest(); 
req.url = "http://www.facebook.com/dialog/feed"; 
var vars:URLVariables = new URLVariables(); 
vars.app_id = "000000000000"; // your application's id 
vars.link = "http://YourSite.com"; 
vars.picture = "https://www.google.com/intl/en_com/images/srpr/logo3w.png"; 
vars.name = "name name"; 
vars.caption = "caption caption caption"; 
vars.description = "description description description"; 
vars.message = "message message message message message"; 
vars.redirect_uri = "http://YourSite.com"; 
req.data = vars; 
req.method = URLRequestMethod.GET; 
navigateToURL(req, "_blank"); 

,但它不是使用Facebook共享者..... 我試了很多很多不同的方式既解決方案結合了,但我得到什麼,但奇怪的網址不工作...

請有人可以幫助我,或告訴我如何使用第二個解決方案,但與共享者?

非常感謝您的幫助

回答

0

您需要OpenGraph Meta標籤(在你的例子above` http://domain.com/pageN.html)添加到您要共享頁面。您在問題中給出的元標記應該添加到那裏,以便Facebook共享腳本可以將其提取出來。

添加<head></head>標籤之間下面的代碼在你的HTML代碼:

<meta name="title" content="my title" /> 
<meta name="description" content="my description" /> 
<link rel="image_src" href="images/thumbnail_image.jpg" /> 
+0

Ooooh好吧,謝謝!問題是這些標籤是在我的as3應用程序中使用深層鏈接動態生成的....相應的html頁面實際上並不存在... – user1425661

+0

這就是爲什麼它不起作用的原因。這些頁面需要存在,即使它是虛擬的。 –

0

我最常做的 - 我創建了一個Facebook應用程序 - 網站與Facebook登錄,添加應用程序域,然後在你的HTML添加此javascript函數:

function postToFacebook(link){    
       var caption = encodeURIComponent("this is cool"); 
       var name = encodeURIComponent("My cool Site"); 
       var pathToPicture = "http://yoursite.com/coolpicture.jpg"; 
       var redirect = "http://yoursite.com/redirect.html"; 
       var id = "123456789098876"; // your application id 
       var theLink = link; // the link you want to share - this is passed as a variable from flash, similary you can pass any variables from flash  

       var fbencoded = "http://www.facebook.com/dialog/feed?app_id=" + id + "&link=" + theLink + "&picture=" + pathToPicture + "&name=" + name + "&caption=" + caption+ "&redirect_uri=" + redirect; 
       window.open(fbencoded, "_blank");   
} 

在閃光時,你只想共享調用這個javascript函數和新的窗口將與Facebook共享窗口中打開:

ExternalInterface.call("postToFacebook", "http://mysite.com/#/cool-page") 

這樣你就可以將任何變量傳遞給該函數。例如,當有人分享時,您可以擁有不同的圖片,這是不可能的,只需meta標籤.....

只有一件事是您必須創建redirect.html - 它必須在您的域中,即鏈接到您的應用程序。在重定向你可以有這樣簡單的事情:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
    <title></title> 
    <meta http-equiv="REFRESH" content="0;url=http://www.facebook.com"> 
</head> 
<body> 

</body> 
</html> 

它只是將用戶重定向到Facebook。 希望這有助於。

0

這是我從AS3中的按鈕使用Share對話框的方式。我希望它可以幫助你

import flash.net.navigateToURL; 

share_btn.addEventListener(MouseEvent.CLICK, shareClickHandler); 

function shareClickHandler(evt:MouseEvent):void 
{ 
    var fb_title = "titulo"; 
    var fb_desc = "descripcion"; 
    var fb_url = "http://mibff.com.mx/"; 
    var fab_img = "http://mibff.com.mx/MiBFF_new.jpg"; 
    var facebookSharer:String = "http://www.facebook.com/sharer.php?s=100&p[title]=" + fb_title + "&p[summary]=" + fb_desc + "&p[url]=" + fb_url + "&p[images][0]=" + fab_img; 
    var jscommand:String = "window.open('" + facebookSharer + "','win','width=626,height=316,toolbar=no,scrollbars=no,resizable=no');"; 
    var sharer:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);"); 
    navigateToURL(sharer,"_self"); 

    //trace(facebookSharer); 
}