Today, we are sharing with you how to post text or midea(videos) in social portal. like facebook, twitter and telegram. we are finding one awesome laravel package for this you can do this things by toolkito/larasap
This is a Laravel package to post your content to social networks such:
Features:
Step : 1 Install Required Packages
First, we are install toolkito/larasap package in our laravel application using following command.
composer require toolkito/larasap
After successfully install package then Run the command below to publish the package config file: config\larasap.php
php artisan vendor:publish --tag=larasap
After run this command config\larasap.php file automatic generated, then open it and configer your required api token and keys. this file look like this.
return [
'telegram' => [
'api_token' => '',
'bot_username' => '',
'channel_username' => '', // Channel username to send message
'channel_signature' => '' // This will be assigned in the footer of message
],
'twitter' => [
'consurmer_key' => '',
'consurmer_secret' => '',
'access_token' => '',
'access_token_secret' => ''
],
'facebook' => [
'app_id' => '',
'app_secret' => '',
'default_graph_version' => '',
'page_access_token' => ''
]
];
[ADDCODE]
Step : 2 Add Following Routes
Next, we are write following route in routes/web.php file.
// Send text message to Telegram Route
Route::get('send-text-message-to-telegram', '[email protected]');
// Send photo to Telegram Route
Route::get('send-photo-to-telegram', '[email protected]');
// Send audio to Telegram Route
Route::get('send-audio-to-telegram', '[email protected]');
// Send document to Telegram Route
Route::get('send-document-to-telegram', '[email protected]');
// Send video to Telegram Route
Route::get('send-video-to-telegram', '[email protected]');
// Send voice to Telegram Route
Route::get('send-voice-to-telegram', '[email protected]');
// Send media group to Telegram Route
Route::get('send-media-group-to-telegram', '[email protected]');
// Send point on the map to Telegram Route
Route::get('send-point-on-the-map-to-telegram', '[email protected]');
// Send information about a venue to Telegram Route
Route::get('send-information-about-a-venue-to-telegram', '[email protected]');
// Send message with inline button to Telegram Route
Route::get('send-message-with-inline-button-to-telegram', '[email protected]');
// Send text tweet Route
Route::get('send-text-tweet', '[email protected]');
// Send tweet with media Route
Route::get('send-tweet-with-media', '[email protected]');
// Send link to Facebook Route
Route::get('send-link-to-facebook', '[email protected]');
// Send photo to Facebook Route
Route::get('send-photo-to-facebook', '[email protected]');
// Send video to Facebook Route
Route::get('send-video-to-facebook', '[email protected]');
Step : 3 Create SocialSharingController.php File
Now, we are create SocialSharingController.php file in app/Http/Controllers folder. and add following sample code.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Toolkito\Larasap\SendTo;
class SocialSharingController extends Controller
{
/**
* Function For Telegram
*/
public function sendTextMessageToTelegram()
{
SendTo::Telegram('Hello, This is testing Laravel social auto posting');
dd('Youe message send successfully!!');
}
public function sendPhotoToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Photo caption (Optional)
[
'type' => 'photo', // Message type (Required)
'file' => 'https://i.imgur.com/j6bzKQc.jpg' // Image url (Required)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendAudioToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Audio caption (Optional)
[
'type' => 'audio', // Message type (Required)
'file' => 'http://example.com/let-me-be-your-lover.mp3', // Audio url (Required)
'duration' => 208, // Duration of the audio in seconds (Optional)
'performer' => 'Enrique Iglesias', // Performer (Optional)
'title' => 'Let Me Be Your Lover' // Track name (Optional)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendDocumentToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Document caption
[
'type' => 'document', // Message type (Required)
'file' => 'http://example.com/larasap.pdf', // Document url (Required)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendVideoToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Video caption (Optional)
[
'type' => 'video', // Message type (Required)
'file' => 'http://example.com/let-me-be-your-lover.mp4', // Audio url (Required)
'duration' => 273, // Duration of sent video in seconds (Optional)
'width' => 1920, // Video width (Optional)
'height' => 1080 // Video height (Optional)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendVoiceToTelegram()
{
SendTo::Telegram(
'Hello, Im testing Laravel social auto posting', // Voice message caption (Optional)
[
'type' => 'voice', // Message type (Required)
'file' => 'https://upload.wikimedia.org/wikipedia/en/9/9f/Sample_of_%22Another_Day_in_Paradise%22.ogg', // Audio url (Required)
'duration' => 28 // Duration of the voice message in seconds (Optional)
],
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendMediaGroupToTelegram()
{
SendTo::Telegram(
null,
[
'type' => 'media_group', // Message type (Required)
'files' => // Array describing photos and videos to be sent, must include 2–10 items
[
[
'type' => 'photo', // Media type (Required)
'media' => 'https://i.imgur.com/j6bzKQc.jpg', // Media url (Required)
'caption' => 'Laravel sccial auto posting' // Media caption (Optional)
],
[
'type' => 'video', // Media type (Required)
'media' => 'http://example.com/let-me-be-your-lover.mp4', // Media url (Required)
'caption' => 'Let me be your lover' // Media caption (Optional)
]
]
]
);
dd('Youe message send successfully!!');
}
public function sendPointOnTheMapToTelegram()
{
SendTo::Telegram(
null,
[
'type' => 'location', // Message type (Required)
'latitude' => 36.1664345, // Latitude of the location (Required)
'longitude' => 58.8209904, // Longitude of the location (Required)
'live_period' => 86400, // Period in seconds for which the location will be updated (Optional)
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendInformationAboutVenueToTelegram()
{
SendTo::Telegram(
null,
[
'type' => 'venue', // Message type (Required)
'latitude' => 36.166048, // Latitude of the location (Required)
'longitude' => 58.822121, // Longitude of the location (Required)
'title' => 'Khayyam', // Name of the venue (Required)
'address' => 'Neyshabur, Razavi Khorasan Province, Iran', // Address of the venue (Required)
'foursquare_id' => '', // Foursquare identifier of the venue (Optional)
'' // Inline keyboard (Optional)
);
dd('Youe message send successfully!!');
}
public function sendMessageWithInlineButtonToTelegram()
{
SendTo::Telegram(
'Laravel social auto posting',
'',
[
[
[
'text' => 'Github',
'url' => 'https://github.com/toolkito/laravel-social-auto-posting'
]
],
[
[
'text' => 'Download',
'url' => 'https://github.com/toolkito/laravel-social-auto-posting/archive/master.zip'
],
]
]
);
// OR
SendTo::Telegram(
'Laravel social auto posting',
'',
[
[
[
'text' => 'Github',
'url' => 'https://github.com/toolkito/laravel-social-auto-posting'
],
[
'text' => 'Download',
'url' => 'https://github.com/toolkito/laravel-social-auto-posting/archive/master.zip'
],
]
]
);
dd('Youe message send successfully!!');
}
/**
* Function For Twitter
*/
public function sendTextTweet()
{
SendTo::Twitter('Hello, Im testing Laravel social auto posting');
dd('Youe message send successfully!!');
}
public function sendTweetWithMedia()
{
SendTo::Twitter(
'Hello, Im testing Laravel social auto posting',
[
public_path('photo-1.jpg'),
public_path('photo-2.jpg')
]
);
dd('Youe message send successfully!!');
}
/**
* Function For Facebook
*/
public function sendLinkToFacebook()
{
SendTo::Facebook(
'link',
[
'link' => 'https://github.com/toolkito/laravel-social-auto-posting',
'message' => 'Laravel social auto posting'
]
);
dd('Youe message send successfully!!');
}
public function sendPhotoToFacebook()
{
SendTo::Facebook(
'photo',
[
'photo' => public_path('img/1.jpg'),
'message' => 'Laravel social auto posting'
]
);
dd('Youe message send successfully!!');
}
public function sendVideoToFacebook()
{
SendTo::Facebook(
'video',
[
'video' => public_path('upload/1.mp4'),
'title' => 'Let Me Be Your Lover',
'description' => 'Let Me Be Your Lover - Enrique Iglesias'
]
);
dd('Youe message send successfully!!');
}
}
Now we are ready to run our example so run bellow command ro quick run:
php artisan serve
Now you can test one by one route url in your browser like that:
http://localhost:8000/send-text-tweet
We are hope you like this tutorials, if any question regarding any query please post your question in our forums click on bellow link Laravelcode's Forums
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Laravel 8 Google Chart Example Tutorial
Google chart is simple, open-source and...How to Get the Current Year using PHP
Use the PHP date() Function You can s...Laravel Generate HTML to PDF with Laravel domPDF
In this article we will share with you h...Laravel Eloquent Has One Through Relationship Tutorial with Example
Laravel provides eloquent relationship w...How to Get Portion of URL Path in JavaScript
Use the window.location Object You ca...