开发者

Detect if a user likes (a Fan of) a Facebook page in Flash

Is there a way for a Flash Facebook app in an iFrame to detect if the user is a fan of the开发者_如何学Python page using the Graph API for Actionscript 3? If not can I achieve the same goal using Javascript? without asking the user for permission (no access token required).


This can be kind of tricky, but I came across a solution a while ago that works for me. You'll probably want to use a JS call (that you can call / get data from using ExternalInterface in your flash). In your JS you'll have something like this :

//me() gets replaced by the current viewer's uid
var fan_qr = 'SELECT source_id FROM connection WHERE target_id = YOUR_APP_ID AND source_id = me()';  

var fan_query = FB.Data.query(fan_qr);
fan_query.wait(function(rows) {

    if(rows[0] && rows[0]['source_id'] != "") {
        //they're a fan
    } else {
        //they're not a fan
    }
}

I forget where I found this originally, but props to that guy for figuring it out.

Since you're getting data about the current user only, you shouldn't need an access token. I know that FB just upped security on FQL calls though, so if you do end up needing an access token, this is how you get it :

FB.getLoginStatus(function(response) {
    if(response.session) {
        //hang on to this for later use
        window.accessToken = response.session.access_token;
    }
});

Then I've seen people adding it directly to the end of the query like this :

var fan_qr = 'SELECT source_id FROM connection WHERE target_id = YOUR_APP_ID AND source_id = me()&access_token=' + window.accessToken; 

If that doesn't work, you can execute the query via FB.api() and simply pass the access_token as an additional argument.

Anyway, hope this helps. Good luck with it!


Finally found the solution. In the page that carries the Facebook app, add:

<?php
$signed_request = $_REQUEST["signed_request"];

list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
$liked = isset($data["page"]["liked"]) ? $data["page"]["liked"] : '';
?>

$liked = true if the logged in user likes the page, false otherwise.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜