2012-05-30 146 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); 
}