Skip to content

Instantly share code, notes, and snippets.

@fastslack
Created April 15, 2016 14:37
Show Gist options
  • Save fastslack/c8ef2bda9fbaab121dfafea78cbc42a8 to your computer and use it in GitHub Desktop.
Save fastslack/c8ef2bda9fbaab121dfafea78cbc42a8 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
/**
* FacebookOauth
*
* @version $Id$
* @package Wellmets
* @subpackage FacebookOauth
* @copyright Copyright 2004 - 2016 Matias Aguirre. All rights reserved.
* @license GNU General Public License version 2 or later.
* @author Matias Aguirre <maguirre@matware.com.ar>
* @link http://www.matware.com.ar
*/
// We are a valid Joomla entry point.
define('_JEXEC', 1);
// Setup the base path related constant.
define('JPATH_BASE', dirname(__FILE__));
// Bootstrap the application.
require dirname(dirname(__FILE__)).'/bootstrap.php';
use Joomla\Registry\Registry;
/**
* FacebookOauth configuration class.
*
* @package Matware
* @since 1.0
*/
final class JConfig
{
public $redirecturi = 'http://your.url.com/';
public $clientid = '99999999999999999';
public $clientsecret = '659e81b7342356eds62a4778ca0fe645f1';
}
/**
* This class checks some common situations that occur when the asset table is corrupted.
*/
// Instantiate the application.
class FacebookOauth extends JApplicationCli
{
/**
* Overrides the parent doExecute method to run the web application.
*
* This method should include your custom code that runs the application.
*
* @return void
*
* @since 1.0
*/
public function __construct()
{
// Call the parent __construct method so it bootstraps the application class.
parent::__construct();
// Getting the parameters
$this->params = new Registry(new JConfig);
// Creating first dabatase instance
$this->_db = JFactory::getDBO();
}
public function execute()
{
// Build the JFacebookOAuth object
$facebookOauth = new JFacebookOAuth($this->params);
// Authenticate. Will redirect to facebook if there is no correct code.
try{
var_dump($facebookOauth->authenticate());
}catch(RuntimeException $e){
$response = new stdClass;
$response->status = 500;
$response->error_message = $e->getMessage();
return false;
}
}
} // end class
// Wrap the execution in a try statement to catch any exceptions thrown anywhere in the script.
try
{
// Instantiate the application object, passing the class name to JCli::getInstance
// and use chaining to execute the application.
JApplicationCli::getInstance('FacebookOauth')->execute();
}
catch (Exception $e)
{
// An exception has been caught, just echo the message.
fwrite(STDOUT, $e->getMessage() . "\n");
exit($e->getCode());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment