as3-facebook-api(フラッシュ用)のFacebook.initメソッドでは、オプションのaccesstokenパラメーターを使用できます。
しかし、.init(...)メソッドの要点は、すべてを初期化することです...アクセストークンは初期化フェーズの副産物です。
では、そもそもアクセストークンを持つことさえ可能であるのです。
(修辞的な答えで応答しないでください...私はアプリを探しています-実用的な答え...ありがとう)。
as3-facebook-api(フラッシュ用)のFacebook.initメソッドでは、オプションのaccesstokenパラメーターを使用できます。
しかし、.init(...)メソッドの要点は、すべてを初期化することです...アクセストークンは初期化フェーズの副産物です。
では、そもそもアクセストークンを持つことさえ可能であるのです。
(修辞的な答えで応答しないでください...私はアプリを探しています-実用的な答え...ありがとう)。
アクセス トークンは特定の期間有効であるため、技術的には再利用できます。または、別の言語を使用して Facebook に接続し、そこからトークンを取得することもできます (思ったよりも一般的です)。
編集 2012/05/24
OK、いくつかのテストを実行し、Facebook AS3 のコードを見た後、これが私が持っているものです:
Object
何もしませんstatus = false
(したがって、init()
呼び出しは になりますFacebook.init( APP_ID, this._onInit, {status:false}, myAccessToken);
)getLoginStatus()
外部イベントを呼び出さないため、いくつかの呼び出しを節約でき、プログラムの起動が速くなります-私が知る限り、それはそれについてです.init()
完全にバイパスし、?access_token=[myToken]
呼び出すときにURLの最後に追加するだけですapi()
(例Facebook.api( "/me?access_token=" + myAccessToken, this._onInfo );
)-またはlibを完全にスキップして、URLLoader
リクエストを行うだけですURLへこのすべてを示す簡単な例。通常どおりアプリを作成し、アプリ ID を置き換えて、通常どおり接続します。あなたのuidとアクセストークンを追跡します。トークンをコピーしてアプリを再起動し、トークンを入力エリアに貼り付けます。今度はこれを使用しますinit()
。
package
{
import com.facebook.graph.data.FacebookAuthResponse;
import com.facebook.graph.Facebook;
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.ui.Keyboard;
import flash.utils.getQualifiedClassName;
/**
* Test facebook connect, showing the init() call with and without an access token. Make a normal
* connection, then copy the access token, and reload. paste your token into the input area to use
* it for the init() call
* @author Damian Connolly
*/
public class Main extends Sprite
{
private static const APP_ID:String = "[SET_YOUR_APP_ID]";
private var m_tf:TextFormat = new TextFormat( "Trebuchet Ms", 9 );
private var m_input:TextField = null; // for adding the token
private var m_log:TextField = null; // for logging our messages
public function Main():void
{
// create our input
this.m_input = new TextField;
this.m_input.defaultTextFormat = this.m_tf;
this.m_input.border = true;
this.m_input.background = true;
this.m_input.type = TextFieldType.INPUT;
this.m_input.text = " ";
this.m_input.width = 700.0;
this.m_input.height = this.m_input.textHeight + 4.0;
this.m_input.text = "";
this.m_input.x = this.m_input.y = 10.0;
this.addChild( this.m_input );
// log and add our mouse listeners
this._log( "Press [SPACE] to init facebook connection, [CTRL] to login, [SHIFT] to get data" );
this._log( "Copy a pre-existing token into the textfield above to use it in the init() call" );
this.stage.addEventListener( KeyboardEvent.KEY_DOWN, this._onKeyDown );
}
// keyboard listener
private function _onKeyDown( e:KeyboardEvent ):void
{
if ( e.keyCode == Keyboard.SPACE )
this._init();
else if ( e.keyCode == Keyboard.CONTROL )
this._login();
else if ( e.keyCode == Keyboard.SHIFT )
this._getData();
}
// init our facebook api
private function _init():void
{
// use our token if we have one
var token:String = ( this.m_input.text != "" ) ? this.m_input.text : null;
this._log( "---------- Initing facebook with token '" + token + "'" );
if ( token == null )
Facebook.init( Main.APP_ID, this._onInit );
else
{
var options:* = { status:false };
Facebook.init( Main.APP_ID, this._onInit, options, token );
}
}
// callback for init
private function _onInit( success:*, fail:* ):void
{
this._log( "Callback for init 2! success: " + success + ", fail: " + fail );
this._log( "Success: " + getQualifiedClassName( success ) );
this._log( "Fail: " + getQualifiedClassName( fail ) );
var response:FacebookAuthResponse = success as FacebookAuthResponse;
if ( response != null )
this._log( "UID: " + response.uid + ", access token: " + response.accessToken );
this._log( ( success != null ) ? "Logged in" : "Not logged in" );
}
// logs into the app if we need to
private function _login():void
{
this._log( "---------- Logging in" );
Facebook.login( this._onLogin );
}
// callback for the login
private function _onLogin( success:*, fail:* ):void
{
this._log( "Callback for _onLogin! success: " + success + ", fail: " + fail );
this._log( "Success: " + getQualifiedClassName( success ) );
this._log( "Fail: " + getQualifiedClassName( fail ) );
var response:FacebookAuthResponse = success as FacebookAuthResponse;
if ( response != null )
this._log( "UID: " + response.uid + ", access token: " + response.accessToken );
}
// gets our data
private function _getData():void
{
this._log( "---------- getting data with url '/me'" );
Facebook.api( "/me", this._onGetData );
}
// callback for our data
private function _onGetData( success:*, fail:* ):void
{
this._log( "Callback for _onLogin! success: " + success + ", fail: " + fail );
this._log( "Success: " + getQualifiedClassName( success ) );
for ( var key:* in success )
this._log( " key '" + key + "' = " + success[key] );
this._log( "Fail: " + getQualifiedClassName( fail ) );
}
// logs a message to the console and our textfield
private function _log( msg:String ):void
{
// create our log if needed
if ( this.m_log == null )
{
this.m_log = new TextField;
this.m_log.defaultTextFormat = this.m_tf;
this.m_log.border = true;
this.m_log.background = true;
this.m_log.width = 700.0;
this.m_log.height = 200.0;
this.m_log.x = this.m_input.x;
this.m_log.y = this.m_input.y + this.m_input.height + 5.0;
this.m_log.wordWrap = true;
this.addChild( this.m_log );
}
trace( msg );
this.m_log.appendText( msg + "\n" );
}
}
}