Exemplo n.º 1
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();
         $influencer = new Influencer(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);
         $influencer->modify(array('_id' => $influencer->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('influencer/social'));
     }
     Alert::once('success', 'Page added successfully', Url::base('influencer/social'));
 }
Exemplo n.º 2
0
 protected function _fetch_facebook($u, &$info, $social)
 {
     try {
         $sdk = new fb\SDK($info['access_token']);
         $details = $sdk->getPageDetails($info['id'])->asArray();
         $insight = json_decode(json_encode($sdk->getInsight($info['id'], 'page_engaged_users', 'week')->asArray()), true);
         $t = MongoDoc::get($insight, 'data.0.values', array(array('value' => 0)));
         $t = $t[count($t) - 1]['value'];
         $info['insights'] = array('engaged_users' => $t);
         $info['details'] = $details;
     } catch (fb\FacebookAccessTokenException $e) {
         $this->_notify_invalidate($u['_id'], $social);
     }
 }