public function info()
 {
     try {
         $token = Setting::get('google-identity', 'access_token');
         if (empty($token)) {
             throw new \Exception('No access token set.');
         }
         $client = new \Google_Client();
         $client->setAccessToken($token);
         $service = new \Google_Service_Oauth2($client);
         $userInfo = $service->userinfo->get();
         return $this->json(['success' => true, 'name' => $userInfo->name, 'email' => $userInfo->email, 'photo' => $userInfo->picture]);
     } catch (\Exception $ex) {
         Setting::set('google-identity', 'access_token', null);
         return $this->json(['success' => false, 'error' => $ex->getMessage()]);
     }
 }
Пример #2
0
 /**
  * Checks whether the API can be called
  *
  * Returns false if the API was called less than a minute ago (which gets over 15 requests in
  * 15 minute on Twitter API rate limiting)
  *
  * @return bool
  */
 public static function canCallAPI()
 {
     $lastCall = Setting::get('twitter', 'last_api_call');
     if ($lastCall == null) {
         return true;
     } else {
         $lastCall = new \DateTime($lastCall);
     }
     $now = new \DateTime();
     $interval = $lastCall->diff($now);
     // Are we at least one minute ago?
     if ($interval->i >= 1) {
         return true;
     } else {
         return false;
     }
 }