我正在努力创建一个类,使得访问Adobe Facebook Graph Api变得更容易,而没有所有细节。这就是我的方法:我有一个FbNewLib.as和一个Test.as作为以及主要的test.fla。
在FbNewLib.as中,我有初始化Facebook api的初始化行。
package
{
import com.facebook.graph.Facebook;
import com.facebook.graph.data.FacebookSession;
import flash.external.ExternalInterface;
public class FbNewLib
{
protected static const app_id:String = "155006914551234" //replace with App Id;
public var scope:String;
public var userId:String;
public var testString:String;
var session:FacebookSession;
public function FbNewLib()
{
trace("FbNewLib initiated.")
}
public function initFacebookLib(scopeString:String):void
{
scope = scopeString;
testString = "testString";
Facebook.init(app_id, onInit);
}
protected function onInit(result:Object, fail:Object):void
{
trace("onInit");
testString = "testStringONINIT";
if (result)
{ //already logged in because of existing session
trace ("On init, already logged in.");
testString = "testStringSUCCESSFUL";
session = Facebook.getSession();
userId = session.uid;
}
else
{
trace("On init, not logged in.");
testString = "testStringUNSUCCESSFUL";
}
}
在我的Test.as中:
public function Test()
{
trace("connected to test.fla");
init_btn.addEventListener(MouseEvent.CLICK, initFbLib);
}
private function initFbLib(e:MouseEvent):void
{
gotoAndStop(2);
var fb:FbNewLib = new FbNewLib();
fb.initFacebookLib("read_stream");
textBox_txt.text = fb.scope + " " + fb.userId + " " + fb.testString;
}
但是,当我在Facebook的testApp中的testApp中测试它时,Facebook.init()不起作用。 textbox_txt中的内容只是“read_stream,null,testString”
有人可以帮忙吗?这甚至可能吗?谢谢!
答案 0 :(得分:0)
这是一种使用Graph API连接到Facebook的方法。一切都在评论中解释。这实际上是连接到Facebook,没有张贴到墙壁或任何东西。这部分可以在这个课程下面找到。
package com.DAL
{
import com.facebook.graph.Facebook;
import flash.events.Event;
import com.facebook.graph.data.FacebookSession;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import com.fbLoginButton;
import com.adobe.serialization.json.JSON;
public class FBConnect extends EventDispatcher
{
/******************************************
* Variables
******************************************/
private var _applicationID:String;
private var _extendedPermissions:Object;
/******************************************
* Constants
******************************************/
public static const CONNECTED:String = "CONNECTED";
/******************************************
* Properties
******************************************/
public function get applicationID():String
{
return _applicationID;
}
/******************************************
* Constructor
******************************************/
public function FBConnect()
{
super();
//Set applicationid
_applicationID = "YOUR_ID";
//Set permissions to ask for
_extendedPermissions = {perms:"read_stream, publish_stream, user_about_me, read_friendlists, user_photos"};
//Initialize facebook
Facebook.init(_applicationID);
}
/******************************************
* Methods
******************************************/
public function login(e:MouseEvent):void
{
Facebook.login(handleLogin, _extendedPermissions);
}
private function handleLogin(response:Object, fail:Object):void
{
dispatchEvent(new Event(CONNECTED));
}
}
}
这应该照顾连接到Facebook。如果你想张贴到墙壁或任何东西,你可以在下面找到一个小例子。
/******************************************
* Constructor
******************************************/
public function FBLogic()
{
super();
_connect = new FBConnect();
_connect.addEventListener(FBConnect.CONNECTED, startLoaders);
initLoaders();
}
/******************************************
* Methods
******************************************/
...
public function post(message:String):void
{
var _params:Object = new Object();
_params.access_token = Facebook.getSession().accessToken;
_params.message = message;
Facebook.api("/" + _userID + "/feed", messagePosted, _params, "POST");
}
public function messagePosted(response:Object, fail:Object):void
{
dispatchEvent(new Event(MESSAGEPOSTED));
}
public function login(e:MouseEvent):void
{
var _loginButton:fbLoginButton = e.target as fbLoginButton;
_loginButton.alpha = 0;
_loginButton.visible = false;
_connect.login(e);
}
如果这不能解决问题,您可能忘记在html文件中添加一些代码。请务必将以下代码添加到html文件的开头:
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
你还需要一个名为fb-root的div,就像这样声明。
<body>
<div id="fb-root"></div>
<div id="flashContent">
</div>
</body>