unshortened URL, and call the 'insert' method on the 'url' resource. Note that we re-store the access_token bundle, just in case anything changed during the request - the main thing that might happen here is the access token itself is refreshed if the application has offline access. ************************************************/ if ($client->getAccessToken() && isset($_GET['url'])) { $url = new Google_Service_Urlshortener_Url(); $url->longUrl = $_GET['url']; $short = $service->url->insert($url); $_SESSION['access_token'] = $client->getAccessToken(); } echo pageHeader("User Query - URL Shortener"); if ($client_id == '<YOUR_CLIENT_ID>' || $client_secret == '<YOUR_CLIENT_SECRET>' || $redirect_uri == '<YOUR_REDIRECT_URI>') { echo missingClientSecretsWarning(); } ?> <div class="box"> <div class="request"> <?php if (isset($authUrl)) { ?> <a class='login' href='<?php echo $authUrl; ?> '>Connect Me!</a> <?php } else { ?> <form id="url" method="GET" action="<?php
function getGoogledata() { include_once APPPATH . "libraries/Google/examples/templates/base.php"; session_start(); //require_once $_SERVER['DOCUMENT_ROOT'] . '/../googleapi.secrets/secrets.inc.php'; require_once APPPATH . "libraries/Google/src/Google/autoload.php"; $client_id = '562916899979-sqstcvrkb5ji1364at447l35sl5pqfa3.apps.googleusercontent.com'; $client_secret = 'JT8lSp-62FHMjbXNqFp2Gy4V'; //$redirect_uri = 'http://roster.plug-point.com/index.php/admin/sites/'; $redirect_uri = 'http://roster.plug-point.com/index.php/admin/sites/getGoogledata'; $client = new Google_Client(); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($redirect_uri); //$client->addScope("https://www.googleapis.com/auth/contacts.readonly"); $client->addScope("https://www.google.com/m8/feeds"); // echo 'call google';exit; if (isset($_REQUEST['logout'])) { unset($_SESSION['access_token']); } if (isset($_GET['code'])) { $client->authenticate($_GET['code']); $_SESSION['access_token'] = $client->getAccessToken(); //$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; //header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); } if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { $client->setAccessToken($_SESSION['access_token']); } else { $authUrl = $client->createAuthUrl(); } //echo $authUrl; exit; if ($client->getAccessToken()) { $_SESSION['access_token'] = $client->getAccessToken(); $access_token = json_decode($client->getAccessToken())->access_token; $url = 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&v=3.0&oauth_token=' . $access_token; $response = file_get_contents($url); } if ($client_id == '<YOUR_CLIENT_ID>' || $client_secret == '<YOUR_CLIENT_SECRET>' || $redirect_uri == '<YOUR_REDIRECT_URI>') { echo missingClientSecretsWarning(); } if (isset($authUrl)) { header('location:' . $authUrl); //echo "<a class='login' href='" . $authUrl . "'>Connect Me!</a>"; } else { // echo "<h3>Results Of Contacts List:</h3>"; $response = str_replace('$', '_', $response); $j = json_decode($response); // echo '<pre>'; $contacts = $j->feed->entry; //var_dump($contacts);exit; for ($i = 0; $i < count($contacts); $i++) { // echo $gcontact=$contacts[$i]->gContact_userDefinedField[0];exit; $name = $contacts[$i]->gd_name->gd_fullName->_t; // $full_name=$contacts[$i]->gd_name[0]->gd_fullName->_t; // $staff_mobile=$contacts[$i]->gd_phoneNumber[0]->_t; $site_name = $contacts[$i]->gd_organization[0]->gd_orgName->_t; $email = $contacts[$i]->gd_email[0]->address; $phone = $contacts[$i]->gd_phoneNumber[0]->_t; $street = $contacts[$i]->gd_structuredPostalAddress[0]->gd_formattedAddress->_t; //echo $street;exit; $city = $contacts[$i]->gd_structuredPostalAddress[0]->gd_city->_t; $postalcode = $contacts[$i]->gd_structuredPostalAddress[0]->gd_postcode->_t; $customs = $contacts[$i]->gContact_userDefinedField; $cluster = $singaporean = $shift1_start = $shift1_end = $shift2_start = $shift2_end = $shift3_start = $shift3_end = $type1 = $ic = $emp_type = $shift_type = $payment_type = $call_preference = $nationality = ''; for ($j = 0; $j < count($customs); $j++) { $key = $customs[$j]->key; if ($key == 'Cluster') { $cluster = $customs[$j]->value; } else { if (strtolower($key) == 'singaporean only') { $singaporean = $customs[$j]->value; } else { if (strtolower($key) == 'shift1 start') { $shift1_start = $customs[$j]->value; } else { if (strtolower($key) == 'shift1 end') { $shift1_end = $customs[$j]->value; } else { if (strtolower($key) == 'shift2 start') { $shift2_start = $customs[$j]->value; } else { if (strtolower($key) == 'shift2 end') { $shift2_end = $customs[$j]->value; } else { if (strtolower($key) == 'shift3 start') { $shift3_start = $customs[$j]->value; } else { if (strtolower($key) == 'shift3 end') { $shift3_end = $customs[$j]->value; } else { if (strtolower($key) == 'type') { $type1 = $customs[$j]->value; } else { if (strtolower($key) == 'ic') { $ic = $customs[$j]->value; } else { if (strtolower($key) == 'employment type') { $emp_type = $customs[$j]->value; } else { if (strtolower($key) == 'shift type') { $shift_type = $customs[$j]->value; } else { if (strtolower($key) == 'payment type') { $payment_type = $customs[$j]->value; } else { if (strtolower($key) == 'call preference') { $call_preference = $customs[$j]->value; } else { if (strtolower($key) == 'nationality') { $nationality = $customs[$j]->value; } } } } } } } } } } } } } } } } //echo ' type='.strtolower($type1); // echo 'ic=' . strtolower($ic); if (strtolower($type1) == 'sites') { //insert into db // echo 'code='.$name;exit; $code_exists = $this->site_model->matchsitecode($name); $date = date('Y-m-d h:i:s', time()); $data = array('code' => $name, 'name' => $site_name, 'phone' => $phone, 'street_name' => $street, 'city' => $city, 'postcode' => $postalcode, 'update_time' => $date); // var_dump($code_exists); if ($code_exists > 0) { //update $this->site_model->updateSite($data, array('code' => $name)); } else { //insert $this->site_model->insertSite($data); if ($shift1_start != null) { $shift1_data = array('site_id' => $siteid, 'shift_type' => $shift_type, 'start_time' => $shift1_start, 'end_time' => $shift1_end); $this->site_model->insertsiteshift($shift1_data); } else { if ($shift2_start != null) { $shift2_data = array('site_id' => $siteid, 'shift_type' => $shift_type, 'start_time' => $shift2_start, 'end_time' => $shift2_end); $this->site_model->insertsiteshift($shift2_data); } } } } if (strtolower($type1) == 'staff') { $staff_data = array('code' => $name, 'name' => $site_name, 'phone' => $phone, 'street_name' => $street, 'city' => $city, 'postcode' => $postalcode, 'update_time' => $date); } } set_message_note('Site Sync Successfully', MESSAGE_NOTE_INFORMATION); redirect(uri_string()); exit; } }
function getGoogledata() { include_once APPPATH . "libraries/Google/examples/templates/base.php"; session_start(); require_once APPPATH . "libraries/Google/src/Google/autoload.php"; $client_id = '354679217715-0f0fu7ejpvmh7m408ll1thjs7vlemmk5.apps.googleusercontent.com'; $client_secret = 'hT9fCTljAoBSUcA5nucxb7FJ'; //$scriptUri = 'http://fingerskies.com/aza_twilio/admin/sites'; $redirect_uri = 'http://fingerskies.com/az-twilio/index.php/admin/sites/getGoogledata'; $client = new Google_Client(); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($redirect_uri); //$client->addScope("https://www.googleapis.com/auth/contacts.readonly"); $client->addScope("https://www.google.com/m8/feeds"); if (isset($_REQUEST['logout'])) { unset($_SESSION['access_token']); } if (isset($_GET['code'])) { $client->authenticate($_GET['code']); //var_dump($client);exit; $_SESSION['access_token'] = $client->getAccessToken(); $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); } if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { $client->setAccessToken($_SESSION['access_token']); } else { $authUrl = $client->createAuthUrl(); } //echo $authUrl; exit; if ($client->getAccessToken()) { $_SESSION['access_token'] = $client->getAccessToken(); $access_token = json_decode($client->getAccessToken())->access_token; //$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results=3&alt=json&v=3.0&oauth_token='.$access_token; //$Gurl = 'https://www.google.com/m8/feeds/groups/default/full?alt=json&v=3.0&oauth_token='.$access_token; //$Gresponse = file_get_contents($Gurl); //echo '<pre>'; //var_dump(json_decode($Gresponse); $url = 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&v=3.0&oauth_token=' . $access_token; $response = file_get_contents($url); } //echo pageHeader("User Query - Multiple APIs"); if ($client_id == '<YOUR_CLIENT_ID>' || $client_secret == '<YOUR_CLIENT_SECRET>' || $redirect_uri == '<YOUR_REDIRECT_URI>') { echo missingClientSecretsWarning(); } if (isset($authUrl)) { echo "<a class='login' href='" . $authUrl . "'>Connect Me!</a>"; } else { echo "<h3>Results Of Contacts List:</h3>"; $response = str_replace('$', '_', $response); //var_dump($response); //$t = str_replace("\n", '', $response); $j = json_decode($response); $j = str_replace('$', '_', $j); echo '<pre>'; // var_dump($j->feed->entry); /* foreach($j->feed->entry as $contacts){ $name = $contacts->title; $email = $contacts->gd$email[0]->address; $phone = $contacts->gd$phoneNumber[0]->$t; $address = $contacts->structuredPostalAddress[0]->gd$formattedAddress; $customs = $contacts->gContact$userDefinedField; foreach ($customs as $f){ $key = $f->key; $val = $f->value; if($key=='Type' && $val=='Sites'){ //Insert into DB echo $name.';'.$email.';'.$phone.';'.$address.';'.$key.';'.$val.'<br/>'; } } } */ file_put_contents('tst.json', $response); } }
function getGoogledata() { include_once APPPATH . "libraries/Google/examples/templates/base.php"; session_start(); //require_once $_SERVER['DOCUMENT_ROOT'] . '/../googleapi.secrets/secrets.inc.php'; require_once APPPATH . "libraries/Google/src/Google/autoload.php"; /* * ********************************************** ATTENTION: Fill in these values! Make sure the redirect URI is to this page, e.g: http://localhost:8080/user-example.php * ********************************************** */ $client_id = '354679217715-0f0fu7ejpvmh7m408ll1thjs7vlemmk5.apps.googleusercontent.com'; $client_secret = 'hT9fCTljAoBSUcA5nucxb7FJ'; //$scriptUri = 'http://fingerskies.com/aza_twilio/admin/sites'; $redirect_uri = 'http://fingerskies.com/az-twilio/index.php/admin/sites/getGoogledata'; /* * ********************************************** Make an API request on behalf of a user. In this case we need to have a valid OAuth 2.0 token for the user, so we need to send them through a login flow. To do this we need some information from our API console project. * ********************************************** */ $client = new Google_Client(); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($redirect_uri); //$client->addScope("https://www.googleapis.com/auth/contacts.readonly"); $client->addScope("https://www.google.com/m8/feeds"); /* * ********************************************** A general service created * ********************************************** */ //$contacts = new Google_Service($client); /* * ********************************************** Boilerplate auth management - see user-example.php for details. * ********************************************** */ if (isset($_REQUEST['logout'])) { unset($_SESSION['access_token']); } if (isset($_GET['code'])) { $client->authenticate($_GET['code']); //var_dump($client);exit; $_SESSION['access_token'] = $client->getAccessToken(); $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); } if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { $client->setAccessToken($_SESSION['access_token']); } else { $authUrl = $client->createAuthUrl(); } //echo $authUrl; exit; /* * ********************************************** If we're signed in, retrieve contacts * ********************************************** */ if ($client->getAccessToken()) { $_SESSION['access_token'] = $client->getAccessToken(); $access_token = json_decode($client->getAccessToken())->access_token; //$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results=3&alt=json&v=3.0&oauth_token='.$access_token; //$Gurl = 'https://www.google.com/m8/feeds/groups/default/full?alt=json&v=3.0&oauth_token='.$access_token; //$Gresponse = file_get_contents($Gurl); //echo '<pre>'; //var_dump(json_decode($Gresponse); $url = 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&v=3.0&oauth_token=' . $access_token; $response = file_get_contents($url); } //echo pageHeader("User Query - Multiple APIs"); if ($client_id == '<YOUR_CLIENT_ID>' || $client_secret == '<YOUR_CLIENT_SECRET>' || $redirect_uri == '<YOUR_REDIRECT_URI>') { echo missingClientSecretsWarning(); } if (isset($authUrl)) { echo "<a class='login' href='" . $authUrl . "'>Connect Me!</a>"; } else { echo "<h3>Results Of Contacts List:</h3>"; $response = str_replace('$', '_', $response); //var_dump($response); //$t = str_replace("\n", '', $response); $j = json_decode($response); $j = str_replace('$', '_', $j); echo '<pre>'; // var_dump($j->feed->entry); /* foreach($j->feed->entry as $contacts){ $name = $contacts->title; $email = $contacts->gd$email[0]->address; $phone = $contacts->gd$phoneNumber[0]->$t; $address = $contacts->structuredPostalAddress[0]->gd$formattedAddress; $customs = $contacts->gContact$userDefinedField; foreach ($customs as $f){ $key = $f->key; $val = $f->value; if($key=='Type' && $val=='Sites'){ //Insert into DB echo $name.';'.$email.';'.$phone.';'.$address.';'.$key.';'.$val.'<br/>'; } } } */ file_put_contents('tst.json', $response); } }
function getGoogledata() { include_once APPPATH . "libraries/Google/examples/templates/base.php"; session_start(); //require_once $_SERVER['DOCUMENT_ROOT'] . '/../googleapi.secrets/secrets.inc.php'; require_once APPPATH . "libraries/Google/src/Google/autoload.php"; $client_id = '562916899979-sqstcvrkb5ji1364at447l35sl5pqfa3.apps.googleusercontent.com'; $client_secret = 'JT8lSp-62FHMjbXNqFp2Gy4V'; $redirect_uri = 'http://roster.plug-point.com/index.php/admin/sites/getGoogledata'; $client = new Google_Client(); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($redirect_uri); $client->addScope("https://www.google.com/m8/feeds"); if (isset($_REQUEST['logout'])) { unset($_SESSION['access_token']); } if (isset($_GET['code'])) { $client->authenticate($_GET['code']); //var_dump($client);exit; $_SESSION['access_token'] = $client->getAccessToken(); $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); } if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { $client->setAccessToken($_SESSION['access_token']); } else { $authUrl = $client->createAuthUrl(); } if ($client->getAccessToken()) { $_SESSION['access_token'] = $client->getAccessToken(); $access_token = json_decode($client->getAccessToken())->access_token; $url = 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&v=3.0&oauth_token=' . $access_token; $response = file_get_contents($url); } //echo pageHeader("User Query - Multiple APIs"); if ($client_id == '<YOUR_CLIENT_ID>' || $client_secret == '<YOUR_CLIENT_SECRET>' || $redirect_uri == '<YOUR_REDIRECT_URI>') { echo missingClientSecretsWarning(); } if (isset($authUrl)) { echo "<a class='login' href='" . $authUrl . "'>Connect Me!</a>"; } else { //echo "<h3>Results Of Contacts List:</h3>"; $response = str_replace('$', '_', $response); //var_dump($response); //$t = str_replace("\n", '', $response); $j = json_decode($response); $j = str_replace('$', '_', $j); echo '<pre>'; // var_dump($j->feed->entry); /* foreach($j->feed->entry as $contacts){ $name = $contacts->title; $email = $contacts->gd$email[0]->address; $phone = $contacts->gd$phoneNumber[0]->$t; $address = $contacts->structuredPostalAddress[0]->gd$formattedAddress; $customs = $contacts->gContact$userDefinedField; foreach ($customs as $f){ $key = $f->key; $val = $f->value; if($key=='Type' && $val=='Sites'){ //Insert into DB echo $name.';'.$email.';'.$phone.';'.$address.';'.$key.';'.$val.'<br/>'; } } } */ file_put_contents('tst.json', $response); } set_message_note('Staff Sync Successfully', MESSAGE_NOTE_INFORMATION); redirect(uri_string()); exit; }