warslett / tweet-sync-doctrine
同步推特和本地Doctrine仓库之间的推文
0.3.2
2019-09-25 14:56 UTC
Requires
- doctrine/orm: >=2.5.0
- symfony/console: >=2.5.0
- symfony/dependency-injection: >=2.5.0
- symfony/yaml: ^3.4
- warslett/tweet-sync: 0.1.*
Requires (Dev)
- behat/behat: ^3.5
- mockery/mockery: ^0.9.4
- phpunit/phpunit: 4.6.*
README
一个同步推特用户最近推文到本地数据库的工具
开始之前
您需要使用 https://apps.twitter.com/ 创建一个应用程序来获取您自己的消费者密钥和消费者密钥。您还需要生成一个带有读取权限的oauth访问令牌和oauth密钥。
安装
composer require warslett/tweet-sync-doctrine
使用Symfony设置
将以下参数添加到您的 parameters.yml 文件中
parameters: warslett_tweet_sync.consumer_key: YOUR_CONSUMER_KEY warslett_tweet_sync.consumer_secret: YOUR_CONSUMER_SECRET warslett_tweet_sync.oauth_access_token: YOUR_OAUTH_ACCESS_TOKEN warslett_tweet_sync.oauth_access_token_secret: YOUR_OAUTH_ACCESS_TOKEN_SECRET
将以下资源添加到 config.yml 文件的导入部分
imports: - { resource: ../../vendor/warslett/tweet-sync-doctrine/src/Resources/config/services_core.yml }
最后,将doctrine映射添加到您的doctrine配置中
doctrine: orm: entity_managers: default: mappings: WArslettTweetSync: mapping: true type: yml dir: %kernel.root_dir%/../vendor/warslett/tweet-sync-doctrine/src/Resources/config/doctrine prefix: WArslett\TweetSync\Model
现在清除您的缓存 php app/console cache:clear
并更新您的数据库模式 php app/console doctrine:schema:update --force
无Symfony设置
在您想要的位置创建自己的Console Runner
#!/usr/bin/env php <?php # app/console // replace with the path to your own autoloader require __DIR__.'/vendor/autoload.php'; use WArslett\TweetSyncDoctrine\ConsoleRunner; ConsoleRunner::configureFromArray([ 'warslett_tweet_sync.consumer_key' => 'YOUR CONSUMER KEY', 'warslett_tweet_sync.consumer_secret' => 'YOUR CONSUMER SECRET', 'warslett_tweet_sync.oauth_access_token' => 'YOUR OAUTH ACCESS TOKEN', 'warslett_tweet_sync.oauth_access_token_secret' => 'YOUR OAUTH ACCESS TOKEN SECRET', 'database.config' => [ // Replace with your own db params // See: http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/configuration.html 'driver' => 'pdo_sqlite', 'path' => __DIR__ . "/db.sqlite" ] ])->run();
然后运行 init 以初始化数据库中的表: php app/console tweetsync:init
(将 app/console 替换为您的 console runner 的位置)
用法
要同步用户 "BBCBreaking" 的推文: php app/console tweetsync:user BBCBreaking
(将 app/console 替换为您的 console runner 的位置)添加到 crontab 以进行定期同步: http://crontab.org/
获取用于在您的应用程序中使用的已同步推文
<?php // replace with the path to your own autoloader require __DIR__.'/vendor/autoload.php'; //In symfony $tweetRepository = $entityManager->getRepository('WArslett\TweetSync\Model\Tweet'); //Not in smyfony $persistenceService = \WArslett\TweetSyncDoctrine\ORM\Doctrine\TweetPersistenceService::create([ // Replace with your own db params // See: http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/configuration.html 'driver' => 'pdo_sqlite', 'path' => __DIR__ . "/db.sqlite" ]); $tweetRepository = $persistenceService->getTweetRepository(); $tweets = $tweetRepository->findByUsername('BBCBreaking'); foreach($tweets as $tweet) { print($tweet->getText()); }