Git Product home page Git Product logo

facebook-poster's Introduction

FacebookPoster Notification Channel For Laravel 5.4

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

This package makes it easly to post on facebook using FacebookPoster Notification with Laravel 5.4

Contents

Installation

You can install this package via composer:

composer require laravel-notification-channels/facebook-poster

Next add the service provider to your config/app.php:

...
'providers' => [
	...
	 NotificationChannels\FacebookPoster\FacebookPosterServiceProvider::class,
],
...

Setting up the Facebook Poster service

You will need to create a Facebook app in order to use this channel. Within in this app you will find the APP Id and APP Secret Key. Place them inside your .env file. In order to load them, add this to your config/services.php file:

...
'facebook_poster' => [
	'app_id'    => getenv('FACEBOOK_APP_ID'),
	'app_secret' => getenv('FACEBOOK_APP_SECRET'),
	'access_token'    => getenv('FACEBOOK_ACCESS_TOKEN'),
]
...

This will load the Facebook app data from the .env file. Make sure to use the same keys you have used there like FACEBOOK_APP_ID.

To create a long time access token for your fan page, open the Graph Api Explorer on the right body heading, select your app then click on the get token button and select Get Page Access Token then select your page and click on the same button again and select Request publish_pages - this will allow app to publish posts to yourpage with your account authorization, after this add access_token parameter into the query string me?fields=id,name,access_token then submit and copy the access token and open this Facebook Debugger Tool and paste your token then click on the Extend Access Token and take the long time expire token value to your env FACEBOOK_ACCESS_TOKEN.

Note : use Facebook Debugger Tool to make sure that your token has these scopes : [ manage_pages, publish_pages, public_profile ]

Usage

Follow Laravel's documentation to add the channel to your Notification class.

Publish Facebook post

use NotificationChannels\FacebookPoster\FacebookPosterChannel;
use NotificationChannels\FacebookPoster\FacebookPosterPost;

class NewsWasPublished extends Notification
{

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [FacebookPosterChannel::class];
    }

    public function toFacebookPoster($notifiable) {
        return new FacebookPosterPost('Laravel notifications are awesome!');
    }
}

Available methods

Take a closer look at the FacebookPosterPost object. This is where the magic happens.

public function toFacebookPoster($notifiable) {
    return new FacebookPosterPost('Laravel notifications are awesome!');
}

Publish Facebook post with link

It is possible to publish link with your post too. You just have to pass the url to the withLink method.

public function toFacebookPoster($notifiable) {
    return (new FacebookPosterPost('Laravel notifications are awesome!'))->withLink('https://laravel.com');
}

Publish Facebook post with image

It is possible to publish image with your post too. You just have to pass the image path to the withImage method.

public function toFacebookPoster($notifiable) {
    return (new FacebookPosterPost('Laravel notifications are awesome!'))->withImage(url('uploads/images/tayee.png'));
}

Notice : withImage accepts absolute url not system paths like /home/user/downloads/image.png

Publish Facebook post with video

It is also possible to publish video with your post too. You just have to pass the video path to the withVideo method.

public function toFacebookPoster($notifiable) {
    return (new FacebookPosterPost('Laravel notifications are awesome!'))
    	->withVideo('bedaer.mp4',[ 'title' => 'My First Video' , 'Description' => 'published by FacebookPoster.' ]);
}

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

facebook-poster's People

Contributors

ahmedash95 avatar freekmurze avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.