Search code examples
facebook-graph-apiauthenticationaccount-kit

AccountKIt-Facebook Set up a page to handle successful logins and exchange authorization codes for access tokens


I have followed everything said accountkit docs:

<?php
// Initialize variables
$app_id = '<facebook_app_id>';
$secret = '<account_kit_app_secret>';
$version = '<account_kit_api_version>'; // 'v1.1' for example

// Method to send Get request to url
function doCurl($url) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $data = json_decode(curl_exec($ch), true);
  curl_close($ch);
  return $data;
}

// Exchange authorization code for access token
$token_exchange_url = 'https://graph.accountkit.com/'.$version.'/access_token?'.
  'grant_type=authorization_code'.
  '&code='.$_POST['code'].
  "&access_token=AA|$app_id|$secret";
$data = doCurl($token_exchange_url);
$user_id = $data['id'];
$user_access_token = $data['access_token'];
$refresh_interval = $data['token_refresh_interval_sec'];

// Get Account Kit information
$me_endpoint_url = 'https://graph.accountkit.com/'.$version.'/me?'.
  'access_token='.$user_access_token;
$data = doCurl($me_endpoint_url);
$phone = isset($data['phone']) ? $data['phone']['number'] : '';
$email = isset($data['email']) ? $data['email']['address'] : '';
?>

The problem is the function doCurl is not returning anything, when I try to var_dump($data) the value is false.

What can I know what to do next to understand what's going on...


Solution

    1. I am developing on the local computer using wamp, so I first checked that cURL is activated on php
    2. After confirming that I looked for article to understand how to use cURL to send requests from php and I found this wonderfull tutorial
    3. After reading I focus on the result returned by curl_exec since mine was returning false and the article says in that case there is error, I use the command to display what the error can be
    4. Error displayed was : curl-error-60-ssl-certificate-unable-to-get-local-issuer-certificate
    5. I search solution on stackoverflow and this question has the solution.

    MY problem is solved.