WordPress.org

Ready to get started?Download WordPress

Forums

Social Connect
[BUG] Facebook access token isn't saved (2 posts)

  1. vasikgreif
    Member
    Posted 4 months ago #

    When trying to get extended access token as described here, I found out that the access token isn't saved at all into db, because the code

    update_user_meta($user->ID,'facebook_token',$access_token);

    in the facebook/callback.php doesn't have the userid, as the user isn't yet logged in.

    Could that be fixed?

    https://wordpress.org/plugins/social-connect/

  2. vasikgreif
    Member
    Posted 4 months ago #

    I think I solved this by adding:

    $sc_access_token = $_REQUEST['social_connect_access_token'];

    And than later saving the value, when the user is created

    update_user_meta($user_id,'facebook_token',$sc_access_token);

    I also found a way to save the extended access token (works only with the new Facebook SDK). I'm passing the user's Facebook ID into this function

    function get_extended_token ($fb_user_id) {
        //facebook application configuration
            try{
                require_once(dirname(__FILE__) . '\lib\facebook-php\src\facebook.php' );
    
            }
            catch(Exception $o){
                print_r($o);
            }
        $config = array(
            'appId' => 'aaa',
            'secret' => '12345',
            'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
        );
    
        $facebook = new Facebook($config);
    
        if($user_id) {
            global $current_user;
            try {
                $access_token = get_user_meta($current_user->ID,'facebook_token',true);
                $facebook->setAccessToken($access_token);
                $facebook->setExtendedAccessToken();
                $access_token = $facebook->getAccessToken();
                update_user_meta($current_user->ID,'facebook_extended_token',$access_token);
            } else {
        }
    }

    Not sure where this code should be put in Social Connect...

Reply

You must log in to post.

About this Plugin

About this Topic