简体   繁体   English

Facebook连接权限PHP SDK

[英]Facebook connect permissions PHP SDK

I try to establish a connection to Facebook Connect, the treatment goes well, I can retrieve the user name and id, but the information transmitted in $ permissions are not taken into account. 我尝试建立与Facebook Connect的连接,处理顺利,我可以检索用户名和ID,但不考虑以$权限传输的信息。 Would I have forgotten a thing? 我会忘记一件事吗? I followed the docs available on Facebook developers. 我关注了Facebook开发人员提供的文档。 I use the latest version: PHP SDK 5.2 我使用的是最新版本: PHP SDK 5.2

public function facebook() {
    session_start();
    require '../Vendor/autoload.php';
    $fb = new Facebook\Facebook([
        'app_id' => 'ID_APP',
        'app_secret' => 'SECRET_APP',
        'default_graph_version' => 'v2.5',
    ]);
    $helper = $fb->getRedirectLoginHelper();
    $permissions = ['email', 'user_location','user_birthday']; // optional
    $loginUrl = $helper->getLoginUrl('http://localhost/Weade/connexion/check_facebook', $permissions);

    $this->redirect($loginUrl);


}

public function check_facebook() {
    session_start();
    require '../Vendor/autoload.php';
    $fb = new Facebook\Facebook([
        'app_id' => 'APP_ID',
        'app_secret' => 'APP_SECRET',
        'default_graph_version' => 'v2.5',
    ]);
    $helper = $fb->getRedirectLoginHelper();
    try {
        $accessToken = $helper->getAccessToken();
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }

    if (isset($accessToken)) {
        // Logged in!
        $_SESSION['facebook_access_token'] = (string) $accessToken;

        // Now you can redirect to another page and use the
        // access token from $_SESSION['facebook_access_token']
    }

    if($this->Session->read('facebook_access_token')) {
        $fb->setDefaultAccessToken($this->Session->read('facebook_access_token'));

        try {
            $response = $fb->get('/me');
            $userNode = $response->getGraphUser();
            debug($userNode);


        } catch(Facebook\Exceptions\FacebookResponseException $e) {
            // When Graph returns an error
            echo 'Graph returned an error: ' . $e->getMessage();
            exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
            // When validation fails or other local issues
            echo 'Facebook SDK returned an error: ' . $e->getMessage();
            exit;
        }

    }

}

Thanks, 谢谢,

$response = $fb->get('/me?fields=emai,user_location,user_birthday');

You'll have to define which fields you want to retrieve with your request, for example /me?fields=id,name,email,birthday instead of just /me 您必须定义要根据请求检索的字段,例如/ me?fields = id,name,email,birthday而不仅仅是/ me

See https://developers.facebook.com/docs/apps/changelog#v2_4 请参阅https://developers.facebook.com/docs/apps/changelog#v2_4

To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. 要尝试提高移动网络的性能,v2.4中的节点和边缘要求您明确请求GET请求所需的字段。 For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data. 例如,GET /v2.4/me/feed默认不再包含喜欢和评论,但GET /v2.4/me/feed?fields=comments,likes将返回数据。 For more details see the docs on how to request specific fields. 有关更多详细信息,请参阅有关如何请求特定字段的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM