/** * syncContacts * - * * @return void */ public function syncContacts() { $token_interface = new StdOAuth2Token($this->token); $google = OAuth::consumer('Google'); $token = $google->getStorage()->storeAccessToken('Google', $token_interface); // get google service $googleService = OAuth::consumer('Google'); // Send a request with it $response = $googleService->request('https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=500'); $result = json_decode($response, true); // Going through the array to clear it and create a new clean array with only the email addresses $vendors = []; // initialize the new array foreach ($result['feed']['entry'] as $contact) { if (isset($contact['gd$email'])) { // Sometimes, a contact doesn't have email address $vendor = Vendor::firstOrNew(array('email' => $contact['gd$email'][0]['address'])); $vendor->phone = isset($contact['gd$phoneNumber']) ? $contact['gd$phoneNumber'][0]['$t'] : ''; $vendor->name = $contact['title']['$t']; $vendor->business = isset($contact['content']) ? $contact['content']['$t'] : ''; $vendor->touch(); array_push($vendors, $vendor); } } return $vendors; }