/** * Gets all the google contacts of authenticated user * @param Request $request * @return mixed */ public function get($request) { $googleService = $this->oAuth->consumer('Google'); $code = $request->code; if (!is_null($code)) { $token = $googleService->requestAccessToken($code); $result = json_decode($googleService->request("https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=400"), true); $contacts = []; foreach ($result['feed']['entry'] as $contact) { if (isset($contact['gd$email'])) { $contacts[] = ['email' => $contact['gd$email'][0]['address'], 'title' => $contact['title']['$t']]; } } $contacts = $this->categorize($contacts); \Session::set('contacts', $contacts); return redirect()->route('contacts'); } else { $url = $googleService->getAuthorizationUri(); return redirect((string) $url); } }
/** * * * @param string $service * @param string $url * @param array $scope * @return \OAuth\Common\Service\AbstractService * @static */ public static function consumer($service, $url = null, $scope = null) { return \Artdarek\OAuth\OAuth::consumer($service, $url, $scope); }