Social Auto Post
This is a lightly and easy to use package to post on your favorite social sites., (*1)
Social Sites Available:
- Twitter
- More sites coming soon.
Installation
type in console:, (*2)
composer require edujugon/social-auto-post
Or update your composer.json file., (*3)
"edujugon/social-auto-post": "1.0.*"
Then, (*4)
composer install
Laravel 5.*
Register the Social service by adding it to the providers array., (*5)
'providers' => array(
...
Edujugon\SocialAutoPost\Providers\SocialAutoPostServiceProvider::class
)
Let's add the Alias facade, add it to the aliases array., (*6)
'aliases' => array(
...
'SocialAutoPost' => Edujugon\SocialAutoPost\Facades\SocialAutoPost::class,
)
Publish the package's configuration file to the application's own config directory, (*7)
php artisan vendor:publish --provider="Edujugon\SocialAutoPost\Providers\SocialAutoPostServiceProvider" --tag="config"
Go to laravel facade sample directly., (*8)
Configuration
The default configuration for all Social sites is located in Config/Config.php, (*9)
Before using this package you should create your app in your social site and then update the config values like follows:, (*10)
'twitter' => [
'consumerKey' => 'YOUR_CONSUMER_KEY',
'consumerSecret' => 'YOUR_CONSUMER_SECRET',
'accessToken' => 'YOUR_ACCESS_TOKEN',
'accessTokenSecret' => 'YOUR_ACCESS_TOKEN_SECRET'
]
You can dynamically set those values or add new ones calling the method config like follows:, (*11)
$social->config(['consumerKey' => 'new_key','accessToken' => 'new_access_token']);
Usage
$social = new SocialAutoPost;
By default it will use Twitter as Social Site but you can also pass the name as parameter:, (*12)
$social = new SocialAutoPost('twitter');
Now you may use any method what you need. Please see the API List., (*13)
API List
Or go to Usage samples directly., (*14)
site
site method sets the social site, which you pass the name through parameter., (*15)
Syntax, (*16)
object site($socialName)
params
params method sets the Post parameters, which you pass through parameter as array., (*17)
Syntax, (*18)
object params(array $data)
Check out the Params Available., (*19)
post
post method sends the post. This method does not return the post response., (*20)
if you want to get the post response you can use withFeedback method chained to this method (post), (*21)
Syntax, (*22)
object post()
withFeedback
withFeedback method provides the post response just after be sent the post., (*23)
Syntax, (*24)
object/array withFeedback()
config
config method sets dynamically the social site app configuration, which you pass through parameter as array., (*25)
Syntax, (*26)
object config(array $data)
getSite
getSite If you want to get the current social site in used, this method gets the social site name., (*27)
Syntax, (*28)
string getSite()
getParams
getParams If you want to get the post parameters, this method may help you., (*29)
Syntax, (*30)
array getParams()
getFeedback
getFeedback If you want to get the very last post feedback, this method may help you., (*31)
Syntax, (*32)
object/null getFeedback()
getConfig
getConfig If you want to get the current social configuration, this method may help you., (*33)
Syntax, (*34)
array getConfig()
Usage samples
You can chain the methods., (*35)
$social = new SocialAutoPost('twitter');
$social->params(['status' => 'My new post #twitter])
->post()
->withFeedback();
or with media, (*36)
$social = new SocialAutoPost('twitter');
$social->params(['status' => 'My new post #twitter,
'media' =>'/path/myImage.jpg'
])
->post()
->withFeedback();
NOTICE that Status cannot be over 140 characters for TWITTER., (*37)
or do it separately, (*38)
$social = new SocialAutoPost('twitter');
$social->params(['status' => 'My new post #twitter])
$social->post();
Params Available
- status
- media (optional)
- local path to your image.
- url to you image.
Getting the Social Site response after posting
There are 2 way to get the post response:, (*39)
1) Chain the method withFeedback() to the post() method., (*40)
```php
$social = new SocialAutoPost('twitter');
$social->params(['status' => 'My new post #twitter])
->post()
->withFeedback();
```
2) You may call the method getFeedback() whenever you want after sending the post., (*41)
```php
$social->getFeedback();
```
Laravel Alias Facade
After register the Alias Facade for this Package, you can use it like follows:, (*42)
SocialAutoPost::site('twitter')
->params(['status' => 'My new post #twitter'])
->post()
->withFeedback();
It will return the post response., (*43)