Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Platform Twitter Bundle Laravel Package

digitalstate/platform-twitter-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. Configure Twitter App Navigate to System → Configuration → Integrations → Twitter Settings in the Oro admin panel.

    • Enter your Twitter API Key, API Secret Key, Access Token, and Access Token Secret.
    • Save the configuration.
  3. 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);
        }
    }
    

Implementation Patterns

Core Workflows

  1. 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
    
  2. Integration with Oro Platform

    • SSO: Use the bundle’s configuration to validate Twitter OAuth tokens in custom SSO logic.
    • Data Sync: Extend the bundle to sync Twitter data (e.g., tweets, users) into Oro entities via Data Connectors or Custom Importers.
  3. 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).

Best Practices

  • Rate Limiting: Handle Twitter\Exception\RateLimitExceededException gracefully with retries or caching.
  • Caching: Cache API responses (e.g., user timelines) using Oro’s oro_cache or Symfony’s Cache component.
  • Error Handling: Wrap TwitterClient calls in try-catch blocks to log TwitterException errors.

Gotchas and Tips

Pitfalls

  1. Missing Configuration

    • If API keys/secrets are invalid, the bundle throws InvalidArgumentException. Validate them early via:
      $this->twitterClient->getApi()->get('account/verify_credentials');
      
    • Fix: Use Oro’s SystemConfiguration to validate keys during save.
  2. Deprecated API Endpoints

    • The bundle may rely on older Twitter API v1.1 endpoints. Monitor deprecations and update endpoints manually (e.g., statuses/user_timelineusers/{id}/tweets).
  3. OAuth Token Rotation

    • Hardcoded tokens in config can break if revoked. Use Oro’s SecretManager to encrypt tokens:
      # config/packages/digitalstate_platform_twitter.yaml
      digitalstate_platform_twitter:
          api:
              access_token: '%env(SECRET_TWITTER_ACCESS_TOKEN)%'
      

Debugging Tips

  • Enable API Debugging: Set TWITTER_DEBUG in .env to log OAuth requests:
    TWITTER_DEBUG=true
    
  • Check Oro Logs: Errors appear in var/log/dev.log (Symfony’s default).

Extension Points

  1. 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
    
  2. 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',
                ],
            ];
        }
    }
    
  3. Webhooks For real-time updates, implement a webhook endpoint in your bundle and use Twitter’s Streaming API (requires custom integration).

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium