Ejemplo n.º 1
0
 protected function _attach()
 {
     try {
         $sdk = new gl\SDK();
         $session = null;
         if ($session = $sdk->obtainToken(Url::base('influencer/social/youtube/'), array(\Google_Service_YouTube::YOUTUBE_READONLY))) {
             $token = $session['refresh_token'];
             $sdk->setRefreshToken($token);
             $youtube = $sdk->getService('youtube');
             $r = $youtube->channels->listChannels('snippet,statistics', array('mine' => 'true'))->getItems();
             if (!count($r)) {
                 throw new \Exception('Unable to fetch channel details');
             }
             /**
              * @var $r \Google_Service_YouTube_ChannelListResponse
              */
             $r = (array) $r[0]->toSimpleObject();
             $r['refresh_token'] = $token;
             $influencer = new Influencer(UserSession::get('user._id'));
             $influencer->modify(array('_id' => $influencer->id), array('$set' => array('social.google-youtube' => $r), '$pull' => array('social_invalidated' => 'google-youtube')));
         }
     } catch (\Google_Service_Exception $e) {
         Alert::once('error', 'Failed to add account: ' . $e->getMessage(), Url::base('influencer/social'));
     }
     Alert::once('success', 'Account added successfully', Url::base('influencer/social'));
 }
Ejemplo n.º 2
0
 protected function _attach()
 {
     try {
         $sdk = new gl\SDK();
         if ($session = $sdk->obtainToken(Url::base('brand/social/gplus/'), array(\Google_Service_Plus::PLUS_LOGIN, \Google_Service_Plus::PLUS_ME, \Google_Service_Plus::USERINFO_PROFILE))) {
             $token = $session['refresh_token'];
             $sdk->setRefreshToken($token);
             $plus = $sdk->getService('plus');
             $me = (array) $plus->people->get('me')->toSimpleObject();
             $me['refresh_token'] = $token;
             $brand = new Brand(UserSession::get('user._id'));
             $brand->modify(array('_id' => $brand->id), array('$set' => array('social.google-plus' => $me), '$pull' => array('social_invalidated' => 'google-plus')));
         }
     } catch (\Google_Service_Exception $e) {
         Alert::once('error', 'Failed to add account: ' . $e->getMessage(), Url::base('brand/social'));
     }
     Alert::once('success', 'Account added successfully', Url::base('brand/social'));
 }
Ejemplo n.º 3
0
 protected function _save()
 {
     try {
         $token = $this->input->post('refresh_token');
         $sdk = new gl\SDK();
         $sdk->setRefreshToken($token);
         $analytics = $sdk->getService('analytics');
         $account = json_decode($this->input->post('account'), true);
         $account = (array) $analytics->management_profiles->get($account['accountId'], $account['webPropertyId'], $account['id'])->toSimpleObject();
         $d = (array) $analytics->data_ga->get('ga:' . $account['id'], '30daysAgo', 'yesterday', 'ga:sessions,ga:avgSessionDuration')->toSimpleObject();
         $account['ga_data'] = $d['totalsForAllResults'];
         $account['refresh_token'] = $token;
         var_dump($account);
         $influencer = new Influencer(UserSession::get('user._id'));
         $influencer->modify(array('_id' => $influencer->id), array('$set' => array('social.google-analytics' => $account), '$pull' => array('social_invalidated' => 'google-analytics')));
     } catch (\Exception $e) {
         Alert::once('error', 'Failed to add page: ' . $e->getMessage(), Url::base('influencer/social'));
     }
     Alert::once('success', 'Page added successfully', Url::base('influencer/social'));
 }
Ejemplo n.º 4
0
 protected function _fetch_google_plus($u, &$info, $social)
 {
     try {
         $token = $info['refresh_token'];
         $sdk = new gl\SDK();
         $sdk->setRefreshToken($token);
         $plus = $sdk->getService('plus');
         $info = (array) $plus->people->get('me')->toSimpleObject();
         $info['refresh_token'] = $token;
     } catch (\Google_Service_Exception $e) {
         $this->_notify_invalidate($u['_id'], $social);
     }
 }