How do I ask for facebook permissions in PHP?

后端 未结 3 1655
借酒劲吻你
借酒劲吻你 2021-01-07 07:36

How do I ask for facebook permissions in PHP? can you please give me an example?

thanks.

相关标签:
3条回答
  • 2021-01-07 08:07

    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.

    0 讨论(0)
  • 2021-01-07 08:10

    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();
    }
    
    0 讨论(0)
  • 2021-01-07 08:14

    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 讨论(0)
提交回复
热议问题