开发者

Flash AS3 : Get Facebook like page's Like Count

开发者 https://www.devze.com 2023-03-29 03:00 出处:网络
I want to display the like count of a page on my flash application. \"When loading my flash app I can send and load a url which can return the count information开发者_如何转开发 of the like page\"

I want to display the like count of a page on my flash application. "When loading my flash app I can send and load a url which can return the count information开发者_如何转开发 of the like page"

anyone know the soultion for this?


It's pretty easy. You just query the link http://graph.facebook.com/?id=[YOUR_SITE] and it'll return a piece of JSON like this:

{
   "id": "YOUR_URL",
   "shares": 11
}

So if you wanted to get the shares for Google, just query http://graph.facebook.com/?id=http://google.com (you can click on the link itself as well).

Use the URLLoader class to load in the data and the AS3CoreLib to convert the JSON to an Object.


as3 :

phpVar.id = "like";
phpVar.selectsize = selectedSize;
phpURLr.method = URLRequestMethod.POST;
phpURLr.data = phpVar;      
phpLoader.dataFormat = URLLoaderDataFormat.TEXT;
phpLoader.load(phpURLr); 

php :

if($_SESSION['test']==''){
            $_SESSION['test'] = 1;
            echo " cond 1 ";
        }
        else {
            echo " cond 2 ";
            $_SESSION['test'] = $_SESSION['test']+1;
        }
        echo " test value = ".$_SESSION['test']; 

......


if all you are concerned about is retreiving the likes value from the JSON object, instead of going thru the trouble of using the JSON parser from AS3CoreLib you could instead just simply read the loaded data as a string and parse it using a regular expression:

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loaderCompleteEventHandler);
loader.load(new URLRequest("https://graph.facebook.com/google"));

function loaderCompleteEventHandler(evt:Event):void
{
    trace("Google Likes: " + evt.currentTarget.data.match(new RegExp("\"likes\":(\\d+),"))[1]);
}

//Google Likes: 3782518
0

精彩评论

暂无评论...
验证码 换一张
取 消