digitalstate/platform-twitter-bundle
Install the Bundle
Add the bundle to your composer.json:
composer require digitalstate/platform-twitter-bundle
Register it in config/bundles.php:
return [
// ...
DigitalState\PlatformTwitterBundle\DigitalStatePlatformTwitterBundle::class => ['all' => true],
];
Configure Twitter App Navigate to System → Configuration → Integrations → Twitter Settings in the Oro admin panel.
First Use Case: Fetching Tweets
Inject the TwitterClient service and fetch tweets:
use DigitalState\PlatformTwitterBundle\Client\TwitterClient;
class MyService
{
public function __construct(private TwitterClient $twitterClient)
{
}
public function fetchUserTweets(string $screenName): array
{
return $this->twitterClient->getUserTimeline($screenName);
}
}
Authentication & API Calls
The bundle abstracts OAuth 1.0a authentication. Use the TwitterClient service for API interactions:
$client->getUserTimeline('orocrm'); // Fetch tweets
$client->searchTweets('laravel'); // Search tweets
Integration with Oro Platform
Event-Driven Extensions
Listen to Oro’s oro_integration.connect or oro_integration.disconnect events to trigger Twitter-specific logic (e.g., sync on connection).
Twitter\Exception\RateLimitExceededException gracefully with retries or caching.oro_cache or Symfony’s Cache component.TwitterClient calls in try-catch blocks to log TwitterException errors.Missing Configuration
InvalidArgumentException. Validate them early via:
$this->twitterClient->getApi()->get('account/verify_credentials');
SystemConfiguration to validate keys during save.Deprecated API Endpoints
statuses/user_timeline → users/{id}/tweets).OAuth Token Rotation
SecretManager to encrypt tokens:
# config/packages/digitalstate_platform_twitter.yaml
digitalstate_platform_twitter:
api:
access_token: '%env(SECRET_TWITTER_ACCESS_TOKEN)%'
TWITTER_DEBUG in .env to log OAuth requests:
TWITTER_DEBUG=true
var/log/dev.log (Symfony’s default).Custom API Methods
Extend TwitterClient via dependency injection:
class CustomTwitterClient extends TwitterClient
{
public function getCustomEndpoint(): array
{
return $this->getApi()->get('custom/endpoint');
}
}
Register as a service in services.yaml:
services:
App\Service\CustomTwitterClient:
decorates: digitalstate_platform_twitter.twitter_client
Data Mapping Use Oro’s Data Connectors to map Twitter data to entities. Example:
// src/Acme/TwitterBundle/Connector/TwitterToOroMapper.php
class TwitterToOroMapper implements DataConnectorMapperInterface
{
public function map(array $twitterData): array
{
return [
'oro_user' => [
'firstName' => $twitterData['name'] ?? '',
'email' => $twitterData['screen_name'] . '@twitter.com',
],
];
}
}
Webhooks For real-time updates, implement a webhook endpoint in your bundle and use Twitter’s Streaming API (requires custom integration).
How can I help you explore Laravel packages today?