-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will allow following hashtags. See the Twitter docs for info about query: https://developer.twitter.com/en/docs/tweets/search/guides/standard-operators
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace spouts\twitter; | ||
|
||
/** | ||
* Spout for fetching a Twitter search | ||
* | ||
* @author Jan Tojnar <[email protected]> | ||
* @copyright Jan Tojnar <[email protected]> | ||
* @license GPL-3.0-or-later | ||
*/ | ||
class Search extends \spouts\twitter\usertimeline { | ||
/** @var string name of source */ | ||
public $name = 'Twitter: search'; | ||
|
||
/** @var string description of this source type */ | ||
public $description = 'Fetch the search results for given query.'; | ||
|
||
/** @var array configurable parameters */ | ||
public $params = [ | ||
'consumer_key' => [ | ||
'title' => 'Consumer Key', | ||
'type' => 'text', | ||
'default' => '', | ||
'required' => true, | ||
'validation' => ['notempty'] | ||
], | ||
'consumer_secret' => [ | ||
'title' => 'Consumer Secret', | ||
'type' => 'password', | ||
'default' => '', | ||
'required' => true, | ||
'validation' => ['notempty'] | ||
], | ||
'access_token' => [ | ||
'title' => 'Access Token (optional)', | ||
'type' => 'text', | ||
'default' => '', | ||
'required' => false, | ||
'validation' => [] | ||
], | ||
'access_token_secret' => [ | ||
'title' => 'Access Token Secret (optional)', | ||
'type' => 'password', | ||
'default' => '', | ||
'required' => false, | ||
'validation' => [] | ||
], | ||
'query' => [ | ||
'title' => 'Search query', | ||
'type' => 'text', | ||
'default' => '', | ||
'required' => true, | ||
'validation' => ['notempty'] | ||
], | ||
]; | ||
|
||
public function load(array $params) { | ||
$this->client = $this->getHttpClient($params['consumer_key'], $params['consumer_secret'], $params['access_token'], $params['access_token_secret']); | ||
|
||
$this->items = $this->fetchTwitterTimeline('search/tweets', [ | ||
'q' => $params['query'], | ||
'result_type' => 'recent', | ||
]); | ||
|
||
$this->htmlUrl = 'https://twitter.com/search?q=' . urlencode($params['query']); | ||
|
||
$this->spoutTitle = "Search twitter for {$params['query']}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters