Gopal Sharma, Author at Codeexecute

How to get the fields value from Facebook Token Meta Data Response?

Facebook SDK to Login with Facebook for my Website:
$accessToken = YOUR_ACCESS_TOKEN;
$fb = new Facebook\Facebook([
    'app_id' => fbAppId,
    'app_secret' => fbSecret,
    'default_graph_version' => 'v2.2',
    ]);
$oAuth2Client = $fb->getOAuth2Client(); 
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
echo "<pre>";print_r($tokenMetadata);

By using the above code, I get the following response. How can I get the get the fields value from this array.

Facebook\Authentication\AccessTokenMetadata Object
(
    [metadata:protected] => Array
        (
            [app_id] => APP_ID
            [application] => APP_NAME
            [expires_at] => DateTime Object
                (
                    [date] => 2016-04-09 10:19:12
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [is_valid] => 1
            [issued_at] => DateTime Object
                (
                    [date] => 2016-02-09 10:19:12
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [scopes] => Array
                (
                    [0] => email
                    [1] => publish_actions
                    [2] => public_profile
                )

            [user_id] => USER_ID
        )

)

To fetch all of the metadata use below funcation:


$expiresAt = (array)$tokenMetadata->getField('expires_at');//pass fields name

$expiresDate = $expiresAt['date'];

 

 
 
 
 

How to get months name and month days between two differente dates?

Please try it.

$start_date  = '2015-11-15';
$end_date  = '2015-12-25';
$result = array();
$start_time   = strtotime($start_date);
$end_time   = date('m-Y', strtotime($end_date));

do {
    $month_year = date('m-Y', $start_time);
    $days = date('t', $start_time);

    $result[] = [
        'month_year' => $month_year,
        'days' => $days,
    ];

    $start_time = strtotime('+1 month', $start_time);
} while ($month_year != $end_time);