From de6ba60192cd54909fe5377059b13b8d3403ca32 Mon Sep 17 00:00:00 2001 From: fengyuexingzi Date: Thu, 14 Jun 2018 08:41:20 +0800 Subject: [PATCH] get_access_token --- auth/linkedin/index.php | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/auth/linkedin/index.php b/auth/linkedin/index.php index e078eb7..0381411 100644 --- a/auth/linkedin/index.php +++ b/auth/linkedin/index.php @@ -24,23 +24,6 @@ $tokenInfo = [ 'expires_in' => '1534052395', ]; -if ($tokenInfo['expires_in'] < time()) { - $html = <<获取授权 -EOF; -} else { - $hdrs = [ - 'http' => [ - 'header' => - "Accept: application/json\r\n" . - "Authorization: Bearer ${tokenInfo['access_token']}", - 'timeout' => 2 - ], - ]; - $context = stream_context_create($hdrs); - echo file_get_contents('https://api.linkedin.com/v1/people/~?format=json', 0, $context); -} - function getCodeUrl() { $url = 'https://www.linkedin.com/oauth/v2/authorization?'; @@ -63,4 +46,20 @@ function getCodeUrl() $url = getCodeUrl(); -echo $html; +if ($tokenInfo['expires_in'] < time()) { + $html = <<获取授权 +EOF; + echo $html; +} else { + $hdrs = [ + 'http' => [ + 'header' => + "Accept: application/json\r\n" . + "Authorization: Bearer ${tokenInfo['access_token']}", + 'timeout' => 2 + ], + ]; + $context = stream_context_create($hdrs); + echo file_get_contents('https://api.linkedin.com/v1/people/~?format=json', 0, $context); +} \ No newline at end of file