-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle-api.php
36 lines (28 loc) · 1.18 KB
/
google-api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
class GoogleLoginApi(){
public function GetAccessToken($client_id, $redirect_uri,$client_secret,$code){
$url = 'https://www.googleapis.com/oauth2/v4/token';
$curlPost = 'client_id='.$client_id.'&redirect_uri='.$redirect_uri.'&client_secret='.$client_secret.'&code='.$code.'&grant_type=authorization_code';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$curlPost);
$exec = curl_exec($ch);
$data = json_decode($exec,true);
return $data;
}
public function GetUserProfileInfo($access_token){
$url = 'https://www.googleapis.com/oauth2/v2/userinfo?fields=name, email, gender,id,picture,verified_email';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
$exec = curl_exec($ch);
$data = json_decode($exec,true);
return $data;
}
}
?>