Manually post to social networks is probably better than to use an automated method. But, if you post many new topics every day, the automated post is practically inevitable.
In Laravel, You need a package for your web application to auto-posting website content to the social network.
Larasap is a Laravel package and the easy way to post to the social network. This package makes it easy to post on Twitter, Facebook page, and Telegram channel.
- 🍒 Simple. Easy to use.
- 📝 Send text message to Telegram channel
- 📷 Send photo to Telegram channel
- 🎵 Send audio to Telegram channel
- 📖 Send document to Telegram channel
- 📺 Send video to Telegram channel
- 🔊 Send voice to Telegram channel
- 🎴 Send a group of photos or videos as an album to Telegram channel
- 📍 Send location to Telegram
- 📌 Send venue to Telegram
- 📞 Send contact to Telegram
- 🌐 Send message with URL inline keyboard to Telegram channel
- ✨ Send text and media to Twitter
- 🎉 Send text and media to Facebook
How to use this package in Laravel?
Step 1: Download and install the package via composer:
composer require toolkito/larasap
Step 2: Run the command below to publish the package config file in config\larasap.php
php artisan vendor:publish — tag=larasap
Step 3: Configuration
For posting to Telegram channel you have to create a bot. Talk to @BotFather and generate a Bot API Token, and it goes like this:
Then, configure your Telegram Bot API Token:
For posting to Twitter automatically, you must create a Twitter application. To create a Twitter application, go to https://apps.twitter.com/
Enter the twitter username. In the “Create an application” page, enter the application name, application description, your website URL and continue with the terms and condition and captcha and click the “Create your Twitter application” button.
After that go to the Keys and Access Token tab (Old name — API Keys) and click on the “Create My Access Token” link. Now you can see the API Key, API Secret, Access Token and Access Token Secret in the API Keys tab. Copy this details to Larasap config file.
For posting to Facebook page firstly you need to create a Facebook App, which is required in order to use the API. Sign in to your Facebook Developers account and click the ‘Add a New App’ link as shown below:
After creating your Facebook app in Dashboard you can see your app details. Add this details to your Larasap config file.
Next up, you’re going to need to get a non-expiring Access Token for your page. Firstly, visit the Facebook Graph API Explorer page. You’ll see an ‘Application’ button in the top right as shown below:
As you can see, currently this is set to ‘Graph API Explorer’. Select your Facebook App instead. Now click the ‘get token’ button which you can also see in the image above. Select ‘Get User Access Token’ and make sure the publish_pages, manage_pages and publish_actions permissions are ticked, then click the ‘Get Access Token’ button. Now click the ‘get token’ button again and select your Facebook page. You now have your Access Token which we need to convert into the non-expiring Access Token. To do so, pass your App ID, App Secret, and Access Token into the following URL:
Now copy the token provided.
Step4: Usage Larasap in application controllers
First, add the
use Toolkito\Larasap\SendTo; in your controller.
Next, send the message to your Telegram channel or Twitter account. You can see usage examples in this link: Examples
To learn more check out the package on GitHub.