<commit_before><?php
namespace Tecspro\Bundle\ApiPostBundle\Services;

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphObject;
use Facebook\FacebookRequestException;

class FacebookApi {

    private $container;
    private $em;
    private $context;
    private $config;
    private $session;

    public function __construct($container, $em, $context) {
        $this->container = $container;
        $this->em = $em;
        $this->context = $context;
    }

    /**
     * Configure facebook
     *
     * page appId
     * page secret
     *
     * @return void;
     */
    public function configure($config) {
        $this->config = $config;

        FacebookSession::setDefaultApplication($this->config['appId'], $this->config['secret']);
        // If you already have a valid access token:
        $this->session = new FacebookSession($this->config['token']);
        // If you're making app-level requests:
        $this->session = FacebookSession::newAppSession();
        // To validate the session:
        try {
          $this->session->validate();
        } catch (FacebookRequestException $ex) {
          // Session not valid, Graph API returned an exception with the reason.
          echo $ex->getMessage();
        } catch (\Exception $ex) {
          // Graph API returned info, but it may mismatch the current app or have expired.
          echo $ex->getMessage();
        }
    }

    /**
     * Post facebook
     *
     * @param array $post
     *
     * @return void;
     */
    public function postInPage($post)<commit_msg>cambios en facebook api funciones<commit_after><?php
namespace Tecspro\Bundle\ApiPostBundle\Services;

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphObject;
use Facebook\FacebookRequestException;
use Facebook\FacebookRedirectLoginHelper;

class FacebookApi {

    private $container;
    private $em;
    private $context;
    private $config;
    private $session;

    public function __construct($container, $em, $context) {
        $this->container = $container;
        $this->em = $em;
        $this->context = $context;
    }

    /**
     * Configure facebook
     *
     * page appId
     * page secret
     *
     * @return void;
     */
    public function configure($config) {
        $this->config = $config;

        FacebookSession::setDefaultApplication($this->config['appId'], $this->config['secret']);
        // If you already have a valid access token:
        $this->session = new FacebookSession($this->config['accessToken']);
        // If you're making app-level requests:
        $this->session = FacebookSession::newAppSession();
        // To validate the session:
        try {
            $this->session->validate();
        } catch (FacebookRequestException $ex) {
            // Session not valid, Graph API returned an exception with the reason.
            echo $ex->getMessage();
        } catch (\Exception $ex) {
            // Graph API returned info, but it may mismatch the current app or have expired.
            echo $ex->getMessage();
        }
    }

    public function connectFace($config) {
        $this->config = $config;

        FacebookSession::setDefaultApplication($this->config['appId'], $this->config['secret']);
        // login helper with redirect_uri
        $helper = new FacebookRedirectLoginHelper($this->config['url']);
        
        try {
          $this->session = $helper->getSessionFromRedirect();
        } catch( FacebookRequestException $ex ) {
          // When Facebook returns an error
        } catch( Exception $ex ) {
          // When validation fails or other local issues
        }
        // see if we have a session
        if ($this->session) {
            // graph api request for user data
            $request = new FacebookRequest( $this->session, 'GET', '/me' );
            $response = $request->execute();
            // get response
            $graphObject = $response->getGraphObject();
            var_dump($graphObject);
            $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
            $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
            $femail = $graphObject->getProperty('email');    // To Get Facebook email ID/
            //header("Location: index.php");
        } else {
            $loginUrl = $helper->getLoginUrl();
            return $loginUrl;
        }

        return null;
    }

    /**
     * Post facebook
     *
     * @param array $post
     *
     * @return void;
     */
    public function postInPage($post)
{'fraction_non_alphanumeric': 0.12172406324453108, 'fraction_numerical': 0.0, 'mean_word_length': 2.20249653259362, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '887599', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1182, 'n_words': 332}