acts/social-api-bundle
Symfony bundle for consuming OAuth 1/2 REST APIs with a simple client and extensible method list. Includes ready-to-use helpers for Facebook and Twitter endpoints, making authenticated requests and handling API responses in your app.
Installation Add the bundle via Composer:
composer require acts/social-api-bundle
Register the bundle in config/app.php under providers:
Camdram\SocialApiBundle\CamdramSocialApiBundle::class,
Configuration Publish the default config:
php artisan vendor:publish --provider="Camdram\SocialApiBundle\CamdramSocialApiBundle" --tag=config
Update config/social_api.php with your API credentials (e.g., facebook, twitter keys/tokens).
First Use Case: Fetching Twitter Data Inject the service into a controller or command:
use Camdram\SocialApiBundle\Service\TwitterService;
public function __construct(TwitterService $twitterService) {
$this->twitterService = $twitterService;
}
Call a method (e.g., fetch user timeline):
$tweets = $this->twitterService->getUserTimeline('username');
Service Integration
FacebookService/TwitterService in controllers, commands, or jobs.use Camdram\SocialApiBundle\Service\FacebookService;
public function handle() {
$posts = $this->facebookService->getPosts('page_id');
// Process posts...
}
OAuth Handling
config/social_api.php:
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect_uri' => env('FACEBOOK_REDIRECT_URI'),
],
getAuthorizationUrl()).Extending APIs
Camdram\SocialApiBundle\Service\AbstractService.LinkedInService:
class LinkedInService extends AbstractService {
protected $baseUri = 'https://api.linkedin.com/v2/';
// Custom methods...
}
Rate Limiting & Caching
$cachedTweets = Cache::remember("twitter_{$username}_timeline", now()->addHours(1), function() use ($username) {
return $this->twitterService->getUserTimeline($username);
});
Error Handling
try {
$data = $this->facebookService->getPost('post_id');
} catch (\Camdram\SocialApiBundle\Exception\ApiException $e) {
Log::error($e->getMessage());
return response()->json(['error' => 'Failed to fetch data'], 500);
}
Deprecated/Archived Status
getUserTimeline() may not support v2’s pagination. Use getUserTweets() instead if available.OAuth Token Management
// Save token after OAuth flow
$token = $this->facebookService->getAccessToken($code);
User::find(auth()->id())->update(['facebook_token' => $token]);
Endpoint Changes
public function getUserTimeline($screenName) {
return $this->callApi('https://api.twitter.com/2/users/by/username/'.$screenName.'/tweets');
}
Rate Limits
try {
$response = $this->callApi($endpoint);
} catch (\Camdram\SocialApiBundle\Exception\RateLimitException $e) {
sleep($e->getRetryAfter());
return $this->callApi($endpoint);
}
Logging
\Log::debug('Twitter API Response', ['data' => $tweets]);
Testing
$this->mock(TwitterService::class)->shouldReceive('getUserTimeline')
->once()->andReturn(['tweet' => 'test']);
Environment-Specific Config
.env for credentials:
FACEBOOK_CLIENT_ID=your_id
TWITTER_CONSUMER_KEY=your_key
Webhooks
HandleIncomingWebhook middleware.Documentation Gaps
How can I help you explore Laravel packages today?