开发者

How do I ask for facebook permissions in PHP?

How do I ask for fac开发者_高级运维ebook permissions in PHP? can you please give me an example?

thanks.


Assuming you have the user's access_token(which you can get via $facebook->getAccessToken() after you've logged a user in:

try{
    $permissions = $facebook->api('/me/permissions', 'get', array('access_token'=>$access_token));
    print_r($permissions, true);
    if(empty($permissions['data'][0]['installed'])){
        echo 'User has not installed the application.';
    }
    if(empty($permissions['data'][0]['publish_stream'])){
        echo 'User does not have the publish_stream permission.';
    }
}catch(Exception $e){
    echo $e->getMessage();
}


It seems that you are new to the Facebook API, I suggest you the following:

  1. Start reading the Facebook Developers Documentation.
  2. Download the Facebook PHP-SDK, there's an example file too..just create your application, insert your app_id and app_secret and you are good to go. (It's highly recommended that you use the PHP-SDK)
  3. To ask for permissions, you can do the following:

    <fb:login-button scope="read_stream"></fb:login-button>
    More about this can be found in this answer too.

  4. You can test all of the above locally, and here's a tutorial that I wrote about how to do it.


This is how you request permissions.. To detect if a user is authorized with your app or not, etc you have to use the Facebook PHP library, that is much more complicated, read here to get started: http://developers.facebook.com/docs/

Just for requesting permission you first need to have your fb-root div and include the Facebook Javascript Graph API file, then put a login button.. The autologoutlink parameter specifies if it should show "Logout" if the user is already connected to your application.

The perms is the permissions requested for the app, a full list is on the Facebook developer docs site.. You have to enter your application ID also.

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<fb:login-button autologoutlink="true" perms="email,user_birthday" size="large" onlogin="window.location = '/';">Connect to this application using Facebook</fb:login-button>
</div>
    <script>
      FB.init({appId: 'ENTER YOUR APPLICATION ID HERE', status: true,
               cookie: true, xfbml: true});
      FB.Event.subscribe('auth.login', function(response) {
        window.location.reload();
      });
    </script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜