Beispiel #1
0
 public function auth()
 {
     $redir = base_url('calendar/google/auth');
     $client = googleClient($redir);
     $myID = getUserID();
     //START FOR CODE
     $code = $this->input->get('code');
     if (!empty($code)) {
         $client->authenticate($code);
         $token = json_decode($client->getAccessToken());
         /*
         $this->session->set_userdata(array(
         	'access_token' => $client->getAccessToken(),
         	'refresh_token' => $token->refresh_token
         ));
         */
         $access_token = $client->getAccessToken();
         $client->setAccessToken($access_token);
         check_tokenExpired($client);
         $service = new Google_Service_Calendar($client);
         $calendarList = $service->calendarList->listCalendarList();
         $nextPagetoken = $calendarList->getNextPageToken();
         $items = array();
         foreach ($calendarList->getItems() as $calendarListEntry) {
             $safeID = $calendarListEntry->getID();
             $events = $service->events->listEvents('primary', array('calendarId' => $safeID));
             foreach ($events->getItems() as $ev) {
                 $dStart = $ev->getStart();
                 $dEnd = $ev->getEnd();
                 $items[] = array('id' => $ev->getID(), 'title' => $ev->getSummary(), 'description' => $ev->getDescription() ? $ev->getDescription() : '', 'start' => $dStart->getDate() ? $dStart->getDate() : $dStart->getDateTime());
             }
         }
         if (count($items)) {
             $this->db->delete('events', array('source' => 'google', 'user_id' => $myID));
             foreach ($items as $item) {
                 $this->db->insert('events', array('title' => $item['title'], 'description' => $item['description'], 'type' => 'default', 'start' => $item['start'], 'end' => $item['start'], 'location' => '', 'date_added' => date("Y-m-d H:i:s"), 'source' => 'google', 'user_id' => $myID));
             }
         }
         redirect(base_url('#/app/calendar'));
     } else {
         echo "Please specify google token.";
     }
 }
Beispiel #2
0
 public function auth()
 {
     $redir = base_url('contacts/google/auth');
     $client = googleClient($redir);
     $myID = getUserID();
     //START FOR CODE
     $code = $this->input->get('code');
     if (!empty($code)) {
         $client->authenticate($code);
         $token = json_decode($client->getAccessToken());
         /*
         $this->session->set_userdata(array(
         	'access_token' => $client->getAccessToken(),
         	'refresh_token' => $token->refresh_token
         ));
         */
         $access_token = $client->getAccessToken();
         $client->setAccessToken($access_token);
         check_tokenExpired($client);
         $service = new Google_Service_Mirror($client);
         $contacts = $service->contacts->listContacts();
         print_r($contacts->getItems());
         foreach ($contacts->getItems() as $contact) {
             print 'Contact ID: ' . $contact->getId();
             print '  > displayName: ' . $contact->getDisplayName();
             if ($contact->getImageUrls() != null) {
                 foreach ($contact->getImageUrls() as $imageUrl) {
                     print '  > imageUrl: ' . $imageUrl;
                 }
             }
         }
         //redirect(base_url('#/app/calendar'));
     } else {
         echo "Please specify google token.";
     }
 }