开发者

facebook application API check if user is application admin in facebook

i have:

    开发者_Go百科
  • user facebook data ( https://graph.facebook.com/btaylor )
  • facebook application data ( https://graph.facebook.com/2439131959 )

Is somehow possible to get if user is application administrator in facebook with this in my hands?


To get this kind of information you can use FQL:

protected function authorizeByFb(){

        $result = $this->fb->api(array(
          'method' => 'fql.query',
          'query'  => "SELECT developer_id FROM developer WHERE application_id='{$appId}' AND developer_id='{$fbUserId}'",
        ));     

        if(count($result)==1){
            return true;
        }

        return false;
    }


if your developed application is checking the role of the logged in facebook user or simply your application wants to recognize it's owner or admin, then http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Faccounts should have that application id listed

api call:

FB.api('/me/accounts', 'get', {"access_token":access_token}, function(response){
    //loop through response to check any application id matches current application id
});

response sample:

{
  "name": "app_name",
  "access_token": "current_token_here",
  "category": "Application",
  "id": "your_owned_app_id"
},
{
  "name": "app_name1",
  "access_token": "current_token_here",
  "category": "Application",
  "id": "your_owned_app1_id"
},


I just got this to work using the Facebook JS API:

FB.api({ method: 'pages.isAdmin', page_id : fbAppId }, function(response){
    if(response){
        alert('the user is an admin');
    }else{
        alert('the user is not an admin')
    }
});

It's using the FB.api method to access the old REST API. This assumes that you've already called FB.init, so make sure that this comes after your init code.

Cheers,
Jeremy


You can get the signed_request and then check if page_admin = 1

<?php
$signed_request = $facebook->getSignedRequest();

$page_admin  = $signed_request["page"]["admin"];
if ( $page_admin == 1 ){ 
echo 'Welcome Admin!';
} 
?>


I tried to attempted javascript form above and found this method to work as an alternative now that the old restful api is depreciated.

function checkAdmin(fbUID, fbAppID){

   FB.api({

    method: 'fql.query',
    query: 'SELECT role FROM app_role WHERE developer_id ='+fbUID+' AND application_id = '+fbAppID

    },
    function(response) {
       if(response.length){
            alert('User is an Admin');
        }
        else{
            alert('User is not an Admin')
        }
    });
 }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜