Skip to content

Instantly share code, notes, and snippets.

@papettoTV
Forked from nojimage/database.php
Created November 17, 2011 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save papettoTV/1373203 to your computer and use it in GitHub Desktop.
Save papettoTV/1373203 to your computer and use it in GitHub Desktop.
CakePHP-TwimとxAuthの実装例
<?php
/**
* for development env
*/
class DATABASE_CONFIG {
public $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'database_name',
'encoding' => 'utf8',
'prefix' => '',
);
public $twitter = array(
'datasource' => 'Twim.TwimSource',
'oauth_consumer_key' => 'YOUR_CONSUMER_KEY',
'oauth_consumer_secret' => 'YOUR_CONSUMER_SECRET',
);
}
<?php
/* @var $this CodeCompletionView */
echo $this->Form->create('User');
echo $this->Form->input('x_auth_username');
echo $this->Form->input('x_auth_password', array('type' => 'password'));
echo $this->Form->end(__('Login', true));
<?php
/* @var $this CodeCompletionView */
echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'tweet')));
echo $this->Form->input('tweet', array('type' => 'textarea'));
echo $this->Form->end(__('Tweet', true));
<?php
class UsersController extends AppController {
public $name = 'Users';
public $uses = array();
public $helpers = array('Twim.Twitter');
public function login() {
if (!empty($this->data)) {
$params = am(array('x_auth_mode' => 'client_auth'), $this->data['User']);
$TwimOauth = ClassRegistry::init('Twim.TwimOauth');
/* @var $TwimOauth TwimOauth */
$accessToken = $TwimOauth->getAccessToken($params);
$this->Session->write('accessToken', $accessToken);
$this->redirect(array('action' => 'tweet'));
}
}
public function tweet() {
if (!empty($this->data)) {
$TwimStatus = ClassRegistry::init('Twim.TwimStatus');
/* @var $TwimStatus TwimStatus */
$accessToken = $this->Session->read('accessToken');
$TwimStatus->getDataSource()->setToken($accessToken);
$this->Session->setFlash(__('tweet now.', true));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment