Flash+Twitter クロスドメインポリシー

Twitterもクロスドメインポリシーの関係でFlashからはAPIに接続できないのでPHP経由で取得
swfと同一階層にphpデータを置いた場合。

var xmlURL:String = "crossdomain-proxy.php?url=この部分を下記に変更"; xmlLoader = new URLLoader(); xmlLoader.load(new URLRequest(xmlURL));

Twitterユーザー全員の発言情報(最新20件)
http://twitter.com/statuses/public_timeline.xml

友達の発言情報(最新20件)
http://twitter.com/statuses/friends_timeline/自分のユーザーネーム か IDナンバー.xml

自分の発言情報(最新20件)
http://twitter.com/statuses/user_timeline/自分のユーザーネーム か IDナンバー.xml

自分の友達のリスト情報
http://twitter.com/statuses/friends/自分のユーザーネーム か IDナンバー.xml

followしてくれているユーザーリスト情報
http://twitter.com/statuses/followers/自分のユーザーネーム か IDナンバー.xml

crossdomain-proxy.phpの内容

<?php
$post_data = $HTTP_RAW_POST_DATA;
$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($post_data);
preg_match("/url=(.*)/",$_SERVER['REQUEST_URI'],$params);
$ch = curl_init( $params[1] );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if ( strlen($post_data)>0 ){
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
$response = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
header("Content-type: text/xml; Content-length: ".strlen($response));
print $response;
}
?>

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です