scripter-co / twitter-stream-bundle
该软件包最新版本(0.1)没有可用的许可信息。
Symfony2的Twitter流软件包
0.1
2013-10-09 20:47 UTC
Requires
- symfony/console: ~2.0
- symfony/framework-bundle: ~2.2
This package is not auto-updated.
Last update: 2024-09-23 14:54:49 UTC
README
一个连接到Twitter流API的Symfony组件,目前仅支持 statuses/filter(见https://dev.twitter.com/docs/api/1.1/post/statuses/filter)
Twitter Stream Bundle简单地
- 连接到Twitter的流API
- 接收任何匹配您的
track关键词的数据。 - 当收到新的推文时触发一个事件
版本
0.1 - 首次发布
安装
将TwitterStreamBundle添加到您的composer.json中
{
"require": {
"scripter-co/twitter-stream-bundle": "dev-master"
}
}
让composer为您获取该软件包
php composer.phar update scripter-co/twitter-stream-bundle
使用方法
在您的组件下创建一个 command(例如 CoreBundle\Command\TwitterStreamCommand.php)并放置
$twitter_request_service = $this->container->get('scripterco_twitter_stream.request');
$twitter_request_service->setConsumerKey('KEY')
->setConsumerSecret('SECRET')
->setToken('TOKEN')
->setTokenSecret('SECRET')
->setKeywords(array(
'my_keyword'
))
->start();
当找到包含您的 my_keyword 关键词的推文时,它将触发一个事件(scripterco_twitter_stream.received),因此我们需要创建一个事件监听器并将其添加到我们的服务文件中
CoreBundle\EventHandler\RequestEventHandler:
<?php
namespace Acme\CoreBundle\EventHandler;
class RequestEventHandler
{
public $_container;
public function __construct($container)
{
$this->_container = $container;
}
public function processTweet($request_event)
{
$tweet_model = $request_event->getTweet();
// tweet id
echo $tweet_model->get('id');
// user screen name
echo $tweet_model->get('user')->get('screen_name')
}
}
注意:如果您想查看所有可用的参数,请参阅这里。
现在,我们只需要将事件监听器添加到服务文件中,我使用的是yaml
acme_core.twitter.event:
class: Acme\CoreBundle\EventHandler\RequestEventHandler
arguments: [@service_container]
tags:
- { name: kernel.event_listener, event: scripterco_twitter_stream.received, method: processTweet }
就是这样,您可以在事件处理器中轻松地将推文保存到数据库中,因为 container 在您的处理器中是可用的。
MIT许可
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.