Installation
composer require dario_swain/wall-poster-bundle:dev-master
(Replace dev-master with a stable version from Packagist.)
Register the Bundle
Add to app/AppKernel.php:
new WallPosterBundle\WallPosterBundle(),
Configure Routing
Import in app/config/routing.yml:
WallPosterBundle:
resource: "@WallPosterBundle/Resources/routing/routing.yml"
Configure API Credentials
Add to app/config/config.yml:
wall_poster:
vk:
access_token: "YOUR_VK_ACCESS_TOKEN"
group_id: "YOUR_VK_GROUP_ID"
facebook:
access_token: "YOUR_FB_ACCESS_TOKEN"
app_id: "YOUR_FB_APP_ID"
page: "YOUR_FB_PAGE_ID"
twitter:
api_key: "YOUR_TWITTER_API_KEY"
api_secret: "YOUR_TWITTER_API_SECRET"
First Use Case Post to VK:
use WallPosterBundle\Service\PosterService;
$poster = $this->get('wall_poster.poster_service');
$poster->postToVk('Hello, social world!');
Posting Content
Use the PosterService to publish to any supported platform:
$poster->postToVk($message, ['attachments' => ['photo123']]);
$poster->postToFacebook($message, ['link' => 'https://example.com']);
$poster->postToTwitter($message);
Handling Captchas (VK-Specific)
If VK blocks your API, use the /wall-poster/captcha route to submit a captcha:
$captchaService = $this->get('wall_poster.captcha_service');
$captchaService->submitCaptcha('captcha_sid', 'captcha_text');
Event-Driven Posting Trigger posts via events (e.g., after a model is saved):
// In your event subscriber
$poster->postToVk("New blog post: {$post->title}");
Batch Posting Loop through items and post sequentially:
foreach ($newsItems as $item) {
$poster->postToFacebook($item->content);
}
Laravel Service Container Bind the bundle’s services to your container for easier access:
$this->app->bind('wall_poster.poster_service', function($app) {
return new PosterService($app['wall_poster.config']);
});
Configuration Overrides
Override defaults in config/packages/wall_poster.yaml (if using Symfony Flex):
wall_poster:
vk:
group_id: "%env(VK_GROUP_ID)%"
Logging Failures Wrap posting logic in a try-catch to log errors:
try {
$poster->postToTwitter($message);
} catch (\Exception $e) {
\Log::error("Twitter post failed: " . $e->getMessage());
}
API Rate Limits
$attempts = 0;
while ($attempts < 3) {
try {
$poster->postToTwitter($message);
break;
} catch (\RuntimeException $e) {
$attempts++;
sleep(2 ** $attempts); // Exponential delay
}
}
Captcha Handling (VK)
/wall-poster/captcha route must be accessible. Ensure:
config.yml.Deprecated Methods
dev-master. Check for breaking changes in future updates (e.g., renamed methods like postToVkontakte → postToVk).Missing Dependencies
guzzlehttp/guzzle is installed (required for HTTP requests):
composer require guzzlehttp/guzzle
Enable Debug Mode
Add to config.yml:
wall_poster:
debug: true
This logs raw API responses for troubleshooting.
Validate Tokens Test tokens manually before integrating:
curl -X GET "https://api.vk.com/method/users.get?access_token=YOUR_TOKEN&v=5.131"
Custom Post Formats
Extend the PosterService to support custom payloads:
class CustomPosterService extends PosterService {
public function postCustomToVk($message, array $options) {
$payload = array_merge([
'message' => $message,
'owner_id' => '-'.$this->config['vk']['group_id'],
], $options);
return $this->httpClient->post('https://api.vk.com/method/wall.post', $payload);
}
}
Add New Platforms
Implement a new poster class (e.g., LinkedInPoster) and register it as a service:
services:
wall_poster.linkedin_poster:
class: App\Service\LinkedInPoster
arguments: ['@wall_poster.config']
Queue Delayed Posts Use Laravel Queues to schedule posts:
$poster->postToVk($message)->delay(now()->addMinutes(10));
(Requires custom queue logic in the bundle.)
Environment Variables
Avoid hardcoding tokens. Use .env:
wall_poster:
vk:
access_token: "%env(VK_ACCESS_TOKEN)%"
(Ensure env() is loaded in config.yml.)
Facebook App Secret
The app_secret is only needed for server-side validation (e.g., webhooks). Omit if unused.
Twitter API v2
The bundle may not support Twitter’s v2 API. Check the source for api_key vs. bearer_token usage.
How can I help you explore Laravel packages today?