พอเชื่อมต่อ login line เข้ามาได้ แต่ไม่ได้ข้อมูลของ user มาด้วยเลยครับ ลอง echo ไม่ออกสักค่าเลย รบกวนด้วยครับ ขอบคุณครับ
<?
session_start();
$client_id = "xxx";
$client_secret = "xxx";
$redirect_uri = "http://xxx/line/check.php";
$token = "";
function getToken($code){
global $client_id, $client_secret,$redirect_uri;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.line.me/v2/oauth/accessToken",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=authorization_code&code=".$code."&client_id=".$client_id."&client_secret=".$client_secret."&redirect_uri=".$redirect_uri,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
function getProfile(){
global $token;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.line.me/v2/profile",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer ".$token,
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
$obj = json_decode(getToken($_GET['code']),true);
$token = $obj['access_token'];
$obj_profile = json_decode(getProfile(),true);
/*print_r($obj);
print_r($obj_profile)*/
/*echo $token ;
echo $obj_profile['displayName'] ;
echo $obj_profile['mid'];
echo $obj_profile['pictureUrl'];
echo $obj_profile['statusMessage'] ;*/
$dp = $obj_profile['displayName'];
$pg = $obj_profile['pictureUrl'];
$ipaddress = $_SERVER['REMOTE_ADDR']; //Get user IP
?>