Skip to content

Instantly share code, notes, and snippets.

@aeknarinamn
Last active July 9, 2019 15:44
Show Gist options
  • Save aeknarinamn/8fe2f2088e2d9c0920713536b93954ac to your computer and use it in GitHub Desktop.
Save aeknarinamn/8fe2f2088e2d9c0920713536b93954ac to your computer and use it in GitHub Desktop.
LINEBOT GET PROFILE
<?php
$userId = "U1a81dc36b7c95042c6ee4718cd5a7c18";
$LINEDatas['url'] = "https://api.line.me/v2/bot/profile/".$userId;
$LINEDatas['token'] = "<YOUR-CHANNEL-ACCESS-TOKEN>";
$results = getLINEProfile($LINEDatas);
file_put_contents('log-profile.txt', $results['message'] . PHP_EOL, FILE_APPEND);
function getLINEProfile($datas)
{
$datasReturn = [];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $datas['url'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer ".$datas['token'],
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
$datasReturn['result'] = 'E';
$datasReturn['message'] = $err;
} else {
if($response == "{}"){
$datasReturn['result'] = 'S';
$datasReturn['message'] = 'Success';
}else{
$datasReturn['result'] = 'E';
$datasReturn['message'] = $response;
}
}
return $datasReturn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment