This plugin provides Twitter API DataSource, Behavior, Components, with OAuth support.
Copyright 2010, ELASTIC Consultants Inc. (http://elasticconsultants.com)
This plugin is no longer being actively developed and maintained.
If you need plugin for Twitter API, please see nojimage/CakePHP-Twim.
- TwitterKit.TwitterSource
- TwitterKit.TwitterBehavior
- TwitterKit.TwitterComponent
- TwitterKit.OauthController
movo to APP/plugins/
git clone http://github.com/elstc/twitter_kit.git
/**
* TwitterSource for none auth
*
* @var array
*/
var $twitter = array(
'driver' => 'TwitterKit.TwitterSource',
);
OR
/**
* TwitterSource using OAuth
*
* @var array
*/
var $twitter = array(
'driver' => 'TwitterKit.TwitterSource',
'oauth_consumer_key' => 'YOUR_CONSUMER_KEY',
'oauth_consumer_secret' => 'YOUR_CONSUMER_SECRET',
'oauth_callback' => 'PATH_TO_OAUTH_CALLBACK_URL',
);
in Controller append $components
var $components = array('TwitterKit.Twitter');
callback example:
function oauth_callback() {
// check params
if (empty($this->params['url']['oauth_token']) || empty($this->params['url']['oauth_verifier'])) {
$this->flash(__('invalid access.', true), '/', 5);
return;
}
// get token
$this->Twitter->setTwitterSource('twitter');
$token = $this->Twitter->getAccessToken();
if (is_string($token)) {
$this->flash(__('fail get access token.', true) . $token, '/', 5);
return;
}
// create save data
$data['User'] = array(
'id' => $token['user_id'],
'username' => $token['screen_name'],
'password' => Security::hash($token['oauth_token']),
'oauth_token' => $token['oauth_token'],
'oauth_token_secret' => $token['oauth_token_secret'],
);
if (!$this->User->save($data)) {
$this->flash(__('user not saved.', true), 'login', 5);
return;
}
$this->Auth->login($data);
// Redirect to Top
$this->redirect('/');
}
in Model append $actsAs
var $actsAs = array('TwitterKit.Twitter');
add methods
- getTwitterSource/setTwitterSource
- twitterSaveToken
- twitterSetToken
- twitterSetTokenById
- etc..
$twitterSource = ConnectionManager::getDataSource('twitter');
$twitterSource->setToken('ACCESS_TOKEN', 'ACCESS_TOKEN_SECRET');
- /twitter_kit/oauth/authorize_url
- /twitter_kit/oauth/authenticate_url
return authorize/authenticate url.
cake/console/cake schema create TwitterKit -path app/plugins/twitter_kit/config/schema/
Licensed under The MIT License. Redistributions of files must retain the above copyright notice.
Copyright 2010, ELASTIC Consultants Inc. (http://elasticconsultants.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This TwitterDataSource Class use HttpSocketOAuth: