class TwitterPostCollector in Social Feed 8
Class TwitterPostCollector.
@package Drupal\socialfeed\Services
Hierarchy
- class \Drupal\socialfeed\Services\TwitterPostCollector
Expanded class hierarchy of TwitterPostCollector
File
- src/
Services/ TwitterPostCollector.php, line 12
Namespace
Drupal\socialfeed\ServicesView source
class TwitterPostCollector {
/**
* The twitter application consumer key.
*
* @var string
*/
protected $consumerKey;
/**
* The twitter application consumer secret.
*
* @var string
*/
protected $consumerSecret;
/**
* The twitter application access token.
*
* @var string
*/
protected $accessToken;
/**
* The twitter application access token secret.
*
* @var string
*/
protected $accessTokenSecret;
/**
* Twitter OAuth client.
*
* @var \Abraham\TwitterOAuth\TwitterOAuth
*/
protected $twitter;
/**
* TwitterPostCollector constructor.
*
* @param string $consumerKey
* $consumerKey.
* @param string $consumerSecret
* $consumerSecret.
* @param string $accessToken
* $accessToken.
* @param string $accessTokenSecret
* $accessTokenSecret.
* @param \Abraham\TwitterOAuth\TwitterOAuth|null $twitter
* Twitter OAuth Client.
*/
public function __construct($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret, TwitterOAuth $twitter = NULL) {
$this->consumerKey = $consumerKey;
$this->consumerSecret = $consumerSecret;
$this->accessToken = $accessToken;
$this->accessTokenSecret = $accessTokenSecret;
$this->twitter = $twitter;
$this
->setTwitterClient();
}
/**
* Set the Twitter client.
*/
public function setTwitterClient() {
if (NULL === $this->twitter) {
$this->twitter = new TwitterOAuth($this->consumerKey, $this->consumerSecret, $this->accessToken, $this->accessTokenSecret);
}
}
/**
* Retrieve Tweets from the given accounts home page.
*
* @param int $count
* The number of posts to return.
*
* @return array
* An array of posts.
*/
public function getPosts($count) {
return $this->twitter
->get('statuses/user_timeline', [
'count' => $count,
'tweet_mode' => 'extended',
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TwitterPostCollector:: |
protected | property | The twitter application access token. | |
TwitterPostCollector:: |
protected | property | The twitter application access token secret. | |
TwitterPostCollector:: |
protected | property | The twitter application consumer key. | |
TwitterPostCollector:: |
protected | property | The twitter application consumer secret. | |
TwitterPostCollector:: |
protected | property | Twitter OAuth client. | |
TwitterPostCollector:: |
public | function | Retrieve Tweets from the given accounts home page. | |
TwitterPostCollector:: |
public | function | Set the Twitter client. | |
TwitterPostCollector:: |
public | function | TwitterPostCollector constructor. |