/**
  * Function to revoke the application access to Facebook account. 
  * @param array ['access_token'=> authorized user access token, 'user_id'=> user id, 'media_id'=> facebook media id, 'permissions'=> user permission to revoke]
  * @return boolean true|false
  * @throws FacebookSDKException if ((user id OR media id) AND access token) OR permission to revoke are missing
  * 
  */
 public function RevokeAccess($params)
 {
     $USER_ID = isset($params[self::USER_ID]) ? $params[self::USER_ID] : null;
     $FACEBOOK_MEDIA_ID = isset($params[self::MEDIA_ID]) ? $params[self::MEDIA_ID] : null;
     $ACCESS_TOKEN = isset($params[self::AUTH_TOKEN]) ? $params[self::AUTH_TOKEN] : null;
     $USER_ID = isset($params[self::USER_ID]) ? $params[self::USER_ID] : null;
     $PERMISSION_TO_REVOKE = isset($params[self::PERMISSIONS]) ? $params[self::PERMISSIONS] : null;
     // 0. Check if permission is set
     //        if(empty($PERMISSION_TO_REVOKE))
     //            throw new FacebookSDKException('Revoke permission is not set.');
     // 1. If IS NOT set access token - get from DB by USER_ID
     if (empty($ACCESS_TOKEN)) {
         if (empty($USER_ID)) {
             throw new FacebookSDKException('To get access token from DB you need to supply USER_ID');
         }
         if (empty($FACEBOOK_MEDIA_ID)) {
             throw new FacebookSDKException('To get access token from DB you need to supply FACEBOOK_MEDIA_ID');
         }
         $params_social = array(\Av\MediaUserModel::MEDIA_ID => $FACEBOOK_MEDIA_ID, \Av\MediaUserModel::USER_ID => $USER_ID);
         $oSocialUserMapper = new \Av\MediaUserModel();
         $access_token_info = $oSocialUserMapper->GetCredentials($params_social);
         $ACCESS_TOKEN = isset($access_token_info[\Av\MediaUserModel::ACCESS_TOKEN]) ? $access_token_info[\Av\MediaUserModel::ACCESS_TOKEN] : null;
         if (empty($ACCESS_TOKEN)) {
             throw new FacebookSDKException("No  access token is saved for USER_ID {$USER_ID}");
         }
     }
     $session = new FacebookSession($ACCESS_TOKEN);
     $request = new FacebookRequest($session, 'DELETE', "/me/permissions/{$PERMISSION_TO_REVOKE}");
     $graphObject = $request->execute()->getGraphObject();
     $this->AddDebug(__METHOD__ . " #" . __LINE__ . "permission {$PERMISSION_TO_REVOKE} deleted with status " . print_r($graphObject, true));
 }
Пример #2
0
 public function findPosts()
 {
     $settings = craft()->plugins->getPlugin('social')->getSettings();
     $user_id = $settings->facebook_user_id;
     $session = $this->getFacebookSession();
     if ($session === false) {
         return array();
     }
     $request = new FacebookRequest($session, 'GET', "/{$user_id}/posts");
     $response = $request->execute();
     $graph_objects = $response->getGraphObjectList();
     $posts = array();
     $f = 'http://www.facebook.com/';
     foreach ($graph_objects as $graph_object) {
         $native = $graph_object->asArray();
         // remove the 'trailing' t.co link
         if (isset($native['message'])) {
             $message = preg_replace('#http://t.co/[^ ]*$#', '', $native['message']);
         } else {
             $message = null;
         }
         // linkify remaining URLs
         $message = preg_replace('/(https?:\\/\\/([A-Za-z0-9-._~:\\/?#\\[\\]@!$&\'()*+,;=%]*))/', '<a href="\\1">\\2</a>', $message);
         $posts[] = array('network' => 'Facebook', 'message' => $message, 'link' => isset($native['link']) ? $native['link'] : $f . $native['id'], 'picture' => isset($native['picture']) ? $native['picture'] : false, 'author' => $native['from']->name, 'author_link' => $f . $native['from']->id, 'created' => strtotime($native['created_time']), 'print_r' => print_r($native, true), 'native' => $native);
     }
     return $posts;
 }
Пример #3
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // Same time next week! :D
     $job = (new \App\Jobs\WeeklyMail())->delay(604800);
     $this->dispatch($job);
     // We'll just want to double-check our Facebook events still exist
     // before we email people about them...
     FacebookSession::setDefaultApplication(getenv('FB_ID'), getenv('FB_SECRET'));
     $session = FacebookSession::newAppSession();
     try {
         $session->validate();
     } catch (FacebookRequestException $ex) {
         // Session not valid, Graph API returned an exception with the reason.
         dd($ex);
     } catch (\Exception $ex) {
         // Graph API returned info, but it may mismatch the current app or have expired.
         dd($ex);
     }
     $all_events = Event::where('time', '>', date('Y-m-d H:i:s'))->where('time', '<', date('Y-m-d H:i:s', time() + 604800))->get();
     foreach ($all_events as $event) {
         $request = new FacebookRequest($session, 'GET', "/" . $event->facebook_id);
         try {
             $response = $request->execute();
         } catch (\Exception $ex) {
             // Facebook Exception looking up event; probably deleted, should mirror here.
             $event->delete();
         }
     }
     foreach (User::where('unsubscribed_email', 'no') as $user) {
         $this->dispatch(new SendEmail($user));
     }
 }
Пример #4
0
 public function makePPonFb($photo)
 {
     $request = new FacebookRequest($this->global, 'GET', '/me/albums');
     $album_id = '';
     $response = $request->execute();
     $graphObject = $response->getGraphObject()->asArray();
     $arr = $graphObject['data'];
     foreach ($arr as $pr) {
         $ar = get_object_vars($pr);
         if ($ar['name'] == 'Profile Pictures') {
             if ($ar['can_upload'] == 1) {
                 $album_id = $ar['id'];
             } else {
                 $album_id = 0;
             }
         }
     }
     /* handle the result */
     if ($album_id != 0) {
         $request = new FacebookRequest($this->global, 'POST', '/' . $album_id . '/photos', array('source' => '@' . $photo));
         $response = $request->execute();
         $graph = $response->getGraphObject()->asArray();
         echo 'https://www.facebook.com/photo.php?fbid=' . $graph['id'] . '&makeprofile=1';
     } else {
         echo '0';
     }
 }
Пример #5
0
 function getUserDataFromFb($session)
 {
     $request = new FacebookRequest($session, 'GET', '/me');
     $response = $request->execute();
     $graphObject = $response->getGraphObject()->asArray();
     return $graphObject;
 }
Пример #6
0
 /**
  * @param $redirect_url
  * @return string|Facebook\GraphUser Login URL or GraphUser
  */
 function connect($redirect_url)
 {
     FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
     $helper = new FacebookRedirectLoginHelper($redirect_url);
     if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
         $session = new FacebookSession($_SESSION['fb_token']);
     } else {
         $session = $helper->getSessionFromRedirect();
     }
     if ($session) {
         try {
             $_SESSION['fb_token'] = $session->getToken();
             $request = new FacebookRequest($session, 'GET', '/me');
             $profile = $request->execute()->getGraphObject('Facebook\\GraphUser');
             if ($profile->getEmail() === null) {
                 throw new \Exception('L\'email n\'est pas disponible');
             }
             return $profile;
         } catch (\Exception $e) {
             unset($_SESSION['fb_token']);
             return $helper->getReRequestUrl(['email']);
         }
     } else {
         return $helper->getLoginUrl(['email']);
     }
 }
Пример #7
0
 public function action_index()
 {
     $gameList = DB::query(Database::SELECT, "SELECT * FROM game")->execute();
     $this->template->content = $gameList[0]['name'];
     require_once Kohana::find_file('vendor', 'vendor/autoload');
     $config = Kohana::$config->load('auth');
     //$session = Session::instance($config['session_type']);
     FacebookSession::setDefaultApplication('376812619137510', 'd054fff7f6146da72c9585d78d0357b5');
     $helper = new FacebookJavaScriptLoginHelper();
     try {
         $session = $helper->getSession();
     } catch (FacebookRequestException $ex) {
         // When Facebook returns an error
         $this->template->content = "fb returned an error";
     } catch (\Exception $ex) {
         // When validation fails or other local issues
         $this->template->content = "validation failed";
         //print_r($ex);
     }
     if (isset($session)) {
         $request = new FacebookRequest($session, 'GET', '/me');
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         if (isset($graphObject->id)) {
             $loginData = array('first_name' => $graphObject->first_name);
         }
         $this->template->content = "Hi, " . $graphObject->getProperty('first_name');
     } else {
         echo "No session";
     }
 }
Пример #8
0
 private function fromFb($action, $method = 'GET')
 {
     $accessToken = \Yii::$app->request->post('accessToken');
     $session = new FacebookSession($accessToken);
     $request = new FacebookRequest($session, $method, $action);
     $response = $request->execute();
     return $response->getGraphObject()->asArray();
 }
Пример #9
0
 public function grabPhotos($albumId)
 {
     $request = new FacebookRequest($this->session, 'GET', '/' . $albumId . '/photos');
     $response = $request->execute();
     $graphObject = $response->getGraphObject();
     $data = $graphObject->getProperty('data');
     return $data;
 }
Пример #10
0
 private function getUserInfo()
 {
     FacebookSession::setDefaultApplication(Config::get('facebook.appid'), Config::get('facebook.secret'));
     $helper = new FacebookRedirectLoginHelper('http://localhost:8000/home');
     $userID = "";
     $userEmail = "";
     $userName = "";
     $userPicUrl = "";
     try {
         $session = $helper->getSessionFromRedirect();
     } catch (FacebookRequestException $ex) {
         // When Facebook returns an error
     } catch (\Exception $ex) {
         // When validation fails or other local issues
     }
     if (isset($_SESSION['token'])) {
         // We have a token, is it valid?
         $session = new FacebookSession($_SESSION['token']);
         try {
             $session->Validate(Config::get('facebook.appid'), Config::get('facebook.secret'));
         } catch (FacebookAuthorizationException $ex) {
             // Session is not valid any more, get a new one.
             $session = '';
         }
     }
     if (isset($session)) {
         $_SESSION['token'] = $session->getToken();
         $request = new FacebookRequest($session, 'GET', '/me?fields=id,name,email,picture');
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         $userID = $graphObject->getProperty('id');
         $userName = $graphObject->getProperty('name');
         $userEmail = $graphObject->getProperty('email');
         $userPicObj = $graphObject->getProperty('picture')->asArray();
         $userPicUrl = $userPicObj['url'];
         $_SESSION['usrID'] = $userID;
         $_SESSION['usrName'] = $userName;
         $_SESSION['usrEmail'] = $userEmail;
         $_SESSION['usrPicUrl'] = $userPicUrl;
         $user_model = App\user::where('user_id', $userID)->first();
         if (is_null($user_model)) {
             $user_model = new App\user();
             $user_model->user_id = $userID;
             $user_model->user_name = $userName;
             $user_model->user_email = $userEmail;
             $user_model->user_profilePic = $userPicUrl;
             $user_model->save();
         } else {
             $user_model->user_name = $userName;
             $user_model->user_email = $userEmail;
             $user_model->user_profilePic = $userPicUrl;
             $user_model->save();
         }
     }
     $data = array("user_id" => $userID, "user_name" => $userName, "user_email" => $userEmail, "user_profilePic" => $userPicUrl);
     $data = array("user_id" => $userID, "user_name" => $userName, "user_email" => $userEmail, "user_profilePic" => $userPicUrl);
     return $data;
 }
Пример #11
0
 public static function deleteTestUser()
 {
     if (!static::$testUserId) {
         return;
     }
     $testUserPath = '/' . static::$testUserId;
     $request = new FacebookRequest(static::getAppSession(), 'DELETE', $testUserPath);
     $request->execute();
 }
Пример #12
0
 private static function _getChannelV4($channel)
 {
     FacebookSession::setDefaultApplication(self::FACEBOOK_APP_ID, self::FACEBOOK_SECRET_KEY);
     $session = FacebookSession::newAppSession(self::FACEBOOK_APP_ID, self::FACEBOOK_SECRET_KEY);
     $request = new FacebookRequest($session, 'GET', '/' . $channel . '/posts?fields=type,created_time,message,picture,object_id,link');
     $response = $request->execute();
     $graphObject = $response->getGraphObject();
     return $graphObject->getPropertyAsArray('data');
 }
Пример #13
0
 /**
  * Retourne l'image principale de l'utilisateur
  * @param  FacebookSession       $session [description]
  * @param  AdvancedUserInterface $user    [description]
  * @return [type]                         [description]
  */
 public function getUserPicture(FacebookSession $session, AdvancedUserInterface $user)
 {
     if (!is_null($user->getFacebookId())) {
         $request = new FacebookRequest($session, 'GET', '/me/picture', ['redirect' => false, 'type' => 'large']);
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         return $graphObject->getProperty('url');
     }
 }
 public function facebook()
 {
     $facebook_default_scope = explode(',', $this->ci->config->item("facebook_default_scope"));
     $facebook_app_id = $this->ci->config->item("facebook_app_id");
     $facebook_api_secret = $this->ci->config->item("facebook_api_secret");
     // init app with app id and secret
     FacebookSession::setDefaultApplication($facebook_app_id, $facebook_api_secret);
     // login helper with redirect_uri
     $helper = new FacebookRedirectLoginHelper(site_url('login/facebook'));
     // see if a existing session exists
     if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
         // create new session from saved access_token
         $session = new FacebookSession($_SESSION['fb_token']);
         // validate the access_token to make sure it's still valid
         try {
             if (!$session->validate()) {
                 $session = null;
             }
         } catch (Exception $e) {
             // catch any exceptions
             $session = null;
         }
     }
     if (!isset($session) || $session === null) {
         // no session exists
         try {
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // When Facebook returns an error
             // handle this better in production code
             print_r($ex);
         } catch (Exception $ex) {
             // When validation fails or other local issues
             // handle this better in production code
             print_r($ex);
         }
     }
     // see if we have a session
     if (isset($session)) {
         // save the session
         $_SESSION['fb_token'] = $session->getToken();
         // create a session using saved token or the new one we generated at login
         $session = new FacebookSession($session->getToken());
         // graph api request for user data
         $request = new FacebookRequest($session, 'GET', '/me');
         $response = $request->execute();
         // get response
         $graphObject = $response->getGraphObject()->asArray();
         $fb_data = array('me' => $graphObject, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
         $this->ci->session->set_userdata('fb_data', $fb_data);
     } else {
         $fb_data = array('me' => null, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
         $this->ci->session->set_userdata('fb_data', $fb_data);
     }
     return $fb_data;
 }
Пример #15
0
 public function example()
 {
     $application = FacebookSession::setDefaultApplication($this->config['app_id'], $this->config['app_secret']);
     $session = FacebookSession::newAppSession();
     $request = new FacebookRequest($session, 'GET', '/780788985274738');
     $response = $request->execute();
     $graphObject = $response->getGraphObject();
     $response = $this->app->json($graphObject->asArray(), 200);
     return $response;
 }
 public function login($data = null)
 {
     if (isset($_SESSION['facebook'])) {
         $session = new FacebookSession($_SESSION['facebook']);
         $request = new FacebookRequest($session, 'GET', '/me');
         $response = $request->execute();
         $graphObject = $response->getGraphObject()->asArray();
         require render_template . "Splash/index.php";
     }
 }
Пример #17
0
    /**
     * Crée un RSS a partir du flux (fb ou non) et le store
     * @param $feed : feed got from the database
     * @return string
     * @throws \Facebook\FacebookRequestException
     */
    public function getRSS($feed)
    {
        //get directly the rss in the storage if exists
        if (Storage::exists($this->rssDirectory . 'feed_' . $feed->id . '.xml')) {
            return Storage::get($this->rssDirectory . 'feed_' . $feed->id . '.xml');
        }
        //if it's a facebook page : convert to rss
        if ($feed->is_facebook) {
            $url = parse_url($feed->url);
            $page = $url['path'];
            $application = array('app_id' => getenv('FACEBOOK_APP_ID'), 'app_secret' => getenv('FACEBOOK_APP_SECRET'));
            FacebookSession::setDefaultApplication($application['app_id'], $application['app_secret']);
            $session = new FacebookSession($application['app_id'] . '|' . $application['app_secret']);
            $request = new FacebookRequest($session, 'GET', '/' . $page . '/feed');
            $response = $request->execute();
            $graphObject = $response->getGraphObject();
            $facebook_feed = $graphObject->asArray();
            $xml = '
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>RSS ' . $feed->name . '</title>
<description></description>
';
            foreach ($facebook_feed['data'] as $entry) {
                //récupere l'id de la page et l'id du post
                $ids = explode('_', $entry->id);
                if ($entry->from->id == $ids[0] && isset($entry->message)) {
                    //si il y a un message et que la page est auteur
                    $title = Str::words($entry->message, 20, '...');
                    //limit mots
                    $pubDate = date("D, d M Y H:i:s T", strtotime($entry->created_time));
                    $item = '
             <item>
             <title><![CDATA[' . $title . ']]></title>
            <link>http://www.facebook.com/' . $ids[0] . '/posts/' . $ids[1] . '</link>
            <pubDate>' . date("r", strtotime($pubDate)) . '</pubDate>
            </item>';
                    $xml .= $item;
                }
            }
            $xml .= '</channel></rss>';
        } else {
            $context = stream_context_create(array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11')));
            $xml = @file_get_contents($feed->url, FALSE, $context);
        }
        $xml = trim($xml);
        // if the file is not xml return false
        $xml_is_valid = @simplexml_load_string($xml);
        if (!$xml_is_valid) {
            throw new \Exception('invalid xml');
        }
        Storage::put($this->rssDirectory . 'feed_' . $feed->id . '.xml', $xml);
        return $xml;
    }
Пример #18
0
 public function getGraph()
 {
     $request = new FacebookRequest($this->session, 'GET', '/me');
     $response = $request->execute();
     return $response->getGraphObject(GraphUser::className());
     //echo "<img src='$image'/>";
     //echo "<br>";
     //echo "Hello $name <br>";
     //echo "Email: $email <br>";
     //echo "Your Facebook ID: $id <br>";
 }
Пример #19
0
/**
 * This function connect to facebook and retrieves the user info
 * If user does not exist in chamilo, it creates it and logs in
 * If user already exists, it updates his info
 */
function facebookConnect()
{
    global $facebook_config;
    global $helper;
    try {
        $helper = new FacebookRedirectLoginHelper($facebook_config['return_url']);
        $session = $helper->getSessionFromRedirect();
        // see if we have a session
        if (isset($session)) {
            // graph api request for user data
            $request = new FacebookRequest($session, 'GET', '/me');
            $response = $request->execute();
            // get response
            $graphObject = $response->getGraphObject();
            $username = changeToValidChamiloLogin($graphObject->getProperty('email'));
            $email = $graphObject->getProperty('email');
            $locale = $graphObject->getProperty('locale');
            $language = facebookPluginGetLanguage($locale);
            if (!$language) {
                $language = 'en_US';
            }
            //Checks if user already exists in chamilo
            $u = array('firstname' => $graphObject->getProperty('first_name'), 'lastname' => $graphObject->getProperty('last_name'), 'status' => STUDENT, 'email' => $graphObject->getProperty('email'), 'username' => $username, 'language' => $language, 'password' => 'facebook', 'auth_source' => 'facebook', 'extra' => array());
            $chamiloUinfo = api_get_user_info_from_email($email);
            if ($chamiloUinfo === false) {
                // we have to create the user
                $chamilo_uid = external_add_user($u);
                if ($chamilo_uid !== false) {
                    $_user['user_id'] = $chamilo_uid;
                    $_user['uidReset'] = true;
                    $_SESSION['_user'] = $_user;
                    header('Location:' . api_get_path(WEB_PATH));
                    exit;
                } else {
                    return false;
                }
            } else {
                // User already exists, update info and login
                $chamilo_uid = $chamiloUinfo['user_id'];
                $u['user_id'] = $chamilo_uid;
                external_update_user($u);
                $_user['user_id'] = $chamilo_uid;
                $_user['uidReset'] = true;
                $_SESSION['_user'] = $_user;
                header('Location:' . api_get_path(WEB_PATH));
                exit;
            }
        }
    } catch (FacebookRequestException $ex) {
        echo $ex;
    } catch (Exception $ex) {
        // When validation fails or other local issues
    }
}
Пример #20
0
 public function getData()
 {
     if (isset($_SESSION['fbData'])) {
         return unserialize($_SESSION['fbData']);
     } else {
         $request = new FacebookRequest($this->session, 'GET', '/me');
         $profile = $request->execute()->getGraphObject('\\zoneroot\\fbconnect\\fbdata');
         $_SESSION['fbData'] = serialize($profile);
         return $profile;
     }
 }
Пример #21
0
 private function createUserProfile(FacebookSession $session, GraphUser $user)
 {
     $profile = new UserProfile();
     $profilePicReq = new FacebookRequest($session, 'GET', '/me/picture', ['redirect' => 0, 'type' => 'large']);
     $pic = $profilePicReq->execute()->getGraphObject()->asArray();
     $profile['displayName'] = $user->getName();
     $profile['profileUrl'] = $user->getLink();
     $profile['imageUrl'] = $pic['url'];
     //TODO other props
     return $profile;
 }
Пример #22
0
 /**
  * login with token
  *
  * @param String $accessToken, $appId, $appSecret
  *
  * @return boolean
  */
 public function loginWithToken($accessToken, $appId, $appSecret)
 {
     FacebookSession::setDefaultApplication($appId, $appSecret);
     $session = new FacebookSession($accessToken);
     $FacebookRequest = new FacebookRequest($session, 'GET', '/me');
     $response = $FacebookRequest->execute();
     $this->graph = $response->getGraphObject(GraphUser::classname());
     if ($session) {
         return true;
     }
     return false;
 }
Пример #23
0
 public function getConfigChannel($id)
 {
     session_start();
     $ch = Helper::getChannel($id);
     // FACEBOOK
     if ($ch->type == 'f') {
         if (!$ch) {
             return "Canal no encontrado";
         }
         if (Input::get('code')) {
             FacebookSession::setDefaultApplication($ch->getParam('APP_ID'), $ch->getParam('APP_SECRET'));
             $helper = new FacebookRedirectLoginHelper(URL::to('social/config/channel/' . $id));
             $session = $helper->getSessionFromRedirect();
             if ($session->validate()) {
                 $request = new FacebookRequest($session, 'GET', '/me/accounts?fields=name,access_token,perms');
                 $pageList = $request->execute()->getGraphObject()->asArray();
                 if ($ch->getParam('PAGE_ID')) {
                     //Comprobamos que la pagina que hemos introducido esta entre las que administra el usuario
                     $page = Facebook::checkIdPage($ch->getParam('PAGE_ID'), $pageList['data']);
                     if ($page) {
                         $ch->setParam('TOKEN', $page->access_token);
                         $ch->setParam('PAGE_NAME', $page->name);
                         return Redirect::to('social/config/channel/' . $id)->with('message', 'Canal configurado con exito , Página ' . $page->name);
                     }
                 }
                 return Redirect::to('social/config/channel/' . $id)->with('error', 'Debe introducir el id de la pagina con la cuel quiere publicar');
             }
         }
         if ($ch->getParam('TOKEN')) {
             // $ch->getTokenInfo();
         }
     }
     // !!
     // TWITTER
     if ($ch->type == 't') {
         //          try{
         //
         //           // $res = file_get_contents('http://tinyurl.com/api-create.php?url=http://stackoverflow.com/questions/22355828/doing-http-requests-from-laravel-to-an-external-api');
         //            //$uploaded_media = Social::Twitter()->uploadMedia(['media' => File::get(public_path('front/images/vilca_logo4.png'))]);
         //            //$res=Social::Twitter()->postTweet(['status' => ' defg  ,jh efg  ,jh  defg  ,jh  defg   defg  ,jh  defg  ,jh  defg  ,j fin '.$res, 'media_ids' => $uploaded_media->media_id_string]);;
         //          //  var_dump( Social::Twitter()->getUserTimeline(['screen_name' => 'thujohn', 'count' => 1, 'format' => 'json'])
         //          );
         //          }catch (\Exception $e){
         //
         //              return Redirect::back()->with('error',$e->getMessage());
         //          }
         // $cfg_tw=Config::get('social.twitter');
     }
     $tmp = array('extends' => Config::get('social::social.tmp.admin', 'layout.base'), 'section_main' => Config::get('social::social.tmp.section_main', 'main'));
     $header_title = array('clase' => 'fa fa-share-alt', 'titulo' => 'Social <small>Config::' . $ch->description . '</small>');
     return View::make('social::configChannel', compact('ch', 'tmp', 'header_title'));
 }
Пример #24
0
 /**
  *
  */
 public function getUrlStats($urls)
 {
     if (!is_array($urls)) {
         $urls = [$urls];
     }
     $query = '/fql?q=select%20like_count,%20comment_count,%20share_count%20from%20link_stat%20where%20url IN ("' . join('","', $urls) . '")';
     $request = new FacebookRequest($this->getSession(), 'GET', $query);
     $response = json_decode($request->execute()->getRawResponse(), true);
     if (sizeof($response['data'] !== sizeof($urls))) {
         // todo как-то залогировать
     }
     return $response['data'];
 }
 public function login(\Illuminate\Cookie\CookieJar $cookieJar, \Request $request)
 {
     // Replace 1234 with your APP_ID
     // Replace 123456789 with your APP_SECRET
     FacebookSession::setDefaultApplication('1234', '123456789');
     $helper = new FacebookRedirectLoginHelper(\Request::url());
     if ($session = $helper->getSessionFromRedirect()) {
         $request = new FacebookRequest($session, 'GET', '/me');
         $userData = $request->execute()->getGraphObject(GraphUser::className());
         $cookieJar->queue(cookie('access_token', $session->getAccessToken(), 45000));
     }
     return redirect($helper->getLoginUrl());
 }
 public function newsAction()
 {
     FacebookSession::setDefaultApplication($this->container->getParameter('client_facebook_id'), $this->container->getParameter('client_facebook_secret'));
     $session = new FacebookSession($this->container->getParameter('client_facebook_id') . '|' . $this->container->getParameter('client_facebook_secret'));
     if ($session) {
         $request = new FacebookRequest($session, 'GET', '/onexposure/?fields=posts{message,picture,created_time,from,link}');
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         $posts = json_decode($response->getRawResponse(), true);
         // var_dump($posts['posts']['data']);
     }
     return $this->render('TNCYSchoolBundle:Default:news.html.twig', array('posts' => $posts['posts']['data']));
 }
Пример #27
0
 private function getPictureLink($objectId, $session)
 {
     if ($session) {
         $request = new FacebookRequest($session, 'GET', "/{$objectId}" . '/picture', array('redirect' => false, 'height' => '200', 'type' => 'normal', 'width' => '200'));
         try {
             $response = $request->execute();
             $graph = $response->getGraphObject()->asArray();
             return $graph['url'];
         } catch (FacebookRequestException $e) {
             return '';
         }
     }
     return '';
 }
Пример #28
0
 public function index()
 {
     $user_data = $this->getUserInfo();
     $user_model = App\user::where('user_id', $user_data['user_id'])->first();
     if ($user_model->user_profilePic2 == '') {
         $session = $this->getSession();
         $request = new FacebookRequest($session, 'GET', '/me?fields=picture.height(200)');
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         $userPicObj = $graphObject->getProperty('picture')->asArray();
         $user_model->user_profilePic2 = $userPicObj['url'];
         $user_model->save();
     }
     $user_data['bigPic'] = $user_model->user_profilePic2;
     return view('profile', $user_data);
 }
function download_album($session, $album_download_directory, $album_id, $album_name)
{
    $request_album_photos = new FacebookRequest($session, 'GET', '/' . $album_id . '/photos?fields=source');
    $response_album_photos = $request_album_photos->execute();
    $album_photos = $response_album_photos->getGraphObject()->asArray();
    $album_directory = $album_download_directory . $album_name;
    if (!file_exists($album_directory)) {
        mkdir($album_directory, 0777);
    }
    $i = 1;
    foreach ($album_photos['data'] as $album_photo) {
        $album_photo = (array) $album_photo;
        file_put_contents($album_directory . '/' . $i . ".jpg", fopen($album_photo['source'], 'r'));
        $i++;
    }
}
 public function fb_upload_test($resourceId, $photoId)
 {
     try {
         FacebookSession::setDefaultApplication($_ENV['fb_app_id'], $_ENV['fb_app_secret']);
         $session = new FacebookSession($_ENV['fb_access_token']);
         $request = new FacebookRequest($session, 'POST', '/1461068850808647/photos', array('source' => 'multipart/form-data', 'url' => 'http://ideasoffsore.com/firebird/public/uploads/4/14088815117et9AeNYzyQ9ePQnxbnY.jpg', 'published' => true, 'message' => "hello this is my photo", 'no_story' => false));
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         if ($graphObject->getProperty("id") != "" && $graphObject->getProperty("post_id") != "") {
             Redirect::to('admin/resources')->with("success", "Successfully uploaded photo");
         } else {
             Redirect::to('admin/resources')->with("error", "Error uploading photo");
         }
     } catch (FacebookApiException $e) {
         return Redirect::to('admin/resources')->with("error", $e);
     }
 }