composer require cvo-technologies/cakephp-twitter
Ensure require
is present in composer.json
:
{
"require": {
"cvo-technologies/cakephp-twitter": "~1.1"
}
}
Plugin::load('Muffin/Webservice', ['bootstrap' => true]);
Plugin::load('CvoTechnologies/Twitter');
Add the following to the Datasources
section of your application config.
'twitter' => [
'className' => 'Muffin\Webservice\Connection',
'service' => 'CvoTechnologies/Twitter.Twitter',
'consumerKey' => '',
'consumerSecret' => '',
'oauthToken' => '',
'oauthSecret' => ''
]
namespace App\Controller;
use Cake\Event\Event;
class StatusesController extends AppController
{
public function beforeFilter(Event $event)
{
$this->loadModel('CvoTechnologies/Twitter.Statuses', 'Endpoint');
}
public function index()
{
$statuses = $this->Statuses->find()->where([
'screen_name' => 'CakePHP',
]);
$this->set('statuses', $statuses);
}
}
This is an example of how to implement the Twitter streaming API.
namespace App\Shell;
use Cake\Console\Shell;
class StreamShell extends Shell
{
public function initialize()
{
$this->modelFactory('Endpoint', ['Muffin\Webservice\Model\EndpointRegistry', 'get']);
$this->loadModel('CvoTechnologies/Twitter.Statuses', 'Endpoint');
}
public function main()
{
$statuses = $this->Statuses
->find('filterStream', [
'word' => 'twitter',
]);
foreach ($statuses as $status) {
echo $status->text . PHP_EOL;
}
}
}