我正在嘗試執行一個Facebook應用程序,該應用程序在畫布頁上運行.swf。我需要獲得Facebook用戶ID,我嘗試使用AS3 Facebook Graph Api,但它不起作用,所以我一直試圖通過調用FB.getUserID();
來獲取ID,並通過獲取Flash獲取ID電影並使用ExternalInterface類調用其中的方法。 我試圖跟蹤是在SWF內的文本字段,但它不工作,我的意思是ID永遠不會到Flash電影。ExternalInterface.callback不起作用
這裏是我的Javascript代碼:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
var swf = null;
FB.init({ appId: 'APP_ID',
status: true,
cookie: true,
xfbml: true,
oauth: true});
FB.Canvas.setAutoResize(false);
FB.Canvas.setSize({ height: 720, width: 600 });
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
var uid = "";
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {
uid = FB.getUserID();
console.log('User Id = '+ uid);
}
else
{
FB.login();
}
});
// Call a flash function exposed with External Interface.
document.getElementById("chimpInvader").setUID(uid);
// Custom Facebook Calls.
// Call getAccessToken() from flash using External Interface,
function getAccessToken(){
FB.login(function(response)
{
if (response.authResponse)
{
var access_token = FB.getAuthResponse()['accessToken'];
//Log your access token so you can be sure the javascript is worjking,.
console.log('Access Token = '+ access_token);
swf = document.getElementById("chimpInvader");
// Call a flash function exposed with External Interface.
swf.setAccessToken(access_token);
}
else
{
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: ''});
}
var movieName = "chimpInvader";
// Get Swf
function getSwf(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
</script>
這裏是一個。至於文件中我的AS3代碼當瑞士法郎運行時調用:
package
{
import flash.display.MovieClip;
import flash.events.ProgressEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.external.ExternalInterface;
public class PreloaderMc extends MovieClip
{
public static var user_id: String = "";
function PreloaderMc():void
{
var mLoader = new Loader();
ExternalInterface.addCallback("setUID", getFId);
var mRequest:URLRequest = new URLRequest ("chimpInvader.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, oncomplete);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loading);
mLoader.load(mRequest);
}
function getFId(uid):void
{
user_id = uid.toString();
txtId.text = "Method Called!";
trace("Getting id");
}
function oncomplete(e:Event)
{
addChild(e.currentTarget.content);
}
function loading(evt:ProgressEvent)
{
var porcentaje:Number = (evt.bytesLoaded/evt.bytesTotal)*100;
trace (porcentaje);
preloadertext.text = String(Math.round(porcentaje));
}
}
}
我真的很感謝所有幫助我可以得到這個事情。
您是否至少在javascript中獲得用戶標識? – Dhiraj
是的,我做過了,我已經通過swfObject傳遞了像flash變量這樣的用戶id來解決這個問題,但是我真的很想知道如何解決這個問題 – j1c1m1b1