Esempio n. 1
0
 protected function _attach()
 {
     try {
         $sdk = new gl\SDK();
         $session = null;
         if ($session = $sdk->obtainToken(Url::base('brand/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;
             $brand = new Brand(UserSession::get('user._id'));
             $brand->modify(array('_id' => $brand->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('brand/social'));
     }
     Alert::once('success', 'Account added successfully', Url::base('brand/social'));
 }
Esempio n. 2
0
 protected function _walk_social($u)
 {
     $user = new Brand(null);
     $update = array();
     printf("%-15s %-30s\n", 'BEGIN', $u['_id']);
     $this->_compute_social($u, $update);
     if ($update) {
         $this->_compute_status_latest($u, $update);
         printf("%-15s %-30s\n", 'UPDATE', $u['_id']);
         $user->modify(array('_id' => $u['_id']), array('$set' => $update));
     }
     printf("%-15s %-30s\n", 'END', $u['_id']);
 }
Esempio n. 3
0
 protected function _attach()
 {
     try {
         $sdk = new tw\SDK();
         if ($session = $sdk->obtainToken(Url::base('brand/social/twitter/' . UserSession::get('user._id')))) {
             $sdk = new tw\SDK($session['oauth_token'], $session['oauth_token_secret']);
             $account = $session;
             $account['details'] = $sdk->getProfile();
             $brand = new Brand(UserSession::get('user._id'));
             $brand->modify(array('_id' => $brand->id), array('$set' => array('social.twitter' => $account), '$pull' => array('social_invalidated' => 'twitter')));
         }
     } catch (tw\TwitterAccessTokenException $e) {
         Alert::once('error', 'Failed to add account: ' . $e->getMessage(), Url::base('brand/social'));
     }
     Alert::once('success', 'Account added successfully', Url::base('brand/social'));
 }
Esempio n. 4
0
 protected function _attach()
 {
     try {
         $sdk = new ig\SDK();
         if ($session = $sdk->obtainToken(Url::base('brand/social/instagram/'))) {
             $session = json_decode(json_encode($session), true);
             $sdk->setAccessToken($session['access_token']);
             $user = $sdk->getUser($session['user']['id']);
             $user['access_token'] = $session['access_token'];
             $brand = new Brand(UserSession::get('user._id'));
             $brand->modify(array('_id' => $brand->id), array('$set' => array('social.instagram' => $user), '$pull' => array('social_invalidated' => 'instagram')));
         }
     } catch (ig\InstagramAccessTokenException $e) {
         Alert::once('error', 'Failed to add account: ' . $e->getMessage(), Url::base('brand/social'));
     }
     Alert::once('success', 'Account added successfully', Url::base('brand/social'));
 }
Esempio n. 5
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'));
 }
Esempio n. 6
0
 protected function _save()
 {
     try {
         $page = json_decode($this->input->post('page_data'), true);
         $sdk = new fb\SDK($page['access_token']);
         $page['details'] = $sdk->getPageDetails($page['id'])->asArray();
         $brand = new Brand(UserSession::get('user._id'));
         $insight = json_decode(json_encode($sdk->getInsight($page['id'], 'page_engaged_users', 'week')->asArray()), true);
         $t = MongoDoc::get($insight, 'data.0.values', array(array('value' => 0)));
         $t = $t[count($t) - 1]['value'];
         $page['insights'] = array('engaged_users' => $t);
         $brand->modify(array('_id' => $brand->id), array('$set' => array('social.facebook' => $page), '$pull' => array('social_invalidated' => 'facebook')));
     } catch (\Exception $e) {
         if ($e instanceof fb\FacebookAccessTokenException) {
             //$brand->invalidate('facebook.page', UserSession::get('user'));
             //(new NotifyNetwork())->invalidate('facebook.page', $brand->get(), UserSession::get('user'));
         }
         Alert::once('error', 'Failed to add page: ' . $e->getMessage(), Url::base('brand/social'));
     }
     Alert::once('success', 'Page added successfully', Url::base('brand/social'));
 }