Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightwatson committed Oct 4, 2019
1 parent 23ffaf9 commit 9123382
Showing 1 changed file with 41 additions and 50 deletions.
91 changes: 41 additions & 50 deletions README.md
Expand Up @@ -4,14 +4,11 @@
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/laravel-notification-channels/facebook-poster/master.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/facebook-poster)
[![StyleCI](https://styleci.io/repos/73361533/shield)](https://styleci.io/repos/73361533)
[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/1e4a812d-aac9-4a85-bcd3-a6df579f5456.svg?style=flat-square)](https://insight.sensiolabs.com/projects/1e4a812d-aac9-4a85-bcd3-a6df579f5456)
[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/facebook-poster.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/facebook-poster)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/facebook-poster/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/facebook-poster/?branch=master)
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/facebook-poster.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/facebook-poster)


This package makes it easly to post on facebook using FacebookPoster Notification with Laravel 5.5+ & 6.0

This package makes it easy to post to Facebook using Laravel notification channels.

## Contents

Expand All @@ -33,32 +30,28 @@ This package makes it easly to post on facebook using FacebookPoster Notificatio

## Installation

You can install this package via composer:
You can install this package via Composer:

``` bash
composer require laravel-notification-channels/facebook-poster
```

### Setting up the Facebook Poster service
### Configuration

You will need to [create](https://developers.facebook.com/apps) a Facebook app in order to use this channel. Within in this app you will find the App ID and secret. Place them inside your `.env` file. In order to load them, add this to your `config/services.php` file:
You will need to [create](https://developers.facebook.com/apps) a Facebook app in order to use this channel. Within in this app you will find the app ID and secret. Place them inside your `.env` file. In order to load them, add this to your `config/services.php` file:

```php
...
'facebook_poster' => [
'client_id' => getenv('FACEBOOK_APP_ID'),
'client_secret' => getenv('FACEBOOK_APP_SECRET'),
'access_token' => getenv('FACEBOOK_ACCESS_TOKEN'),
'client_id' => getenv('FACEBOOK_APP_ID'),
'client_secret' => getenv('FACEBOOK_APP_SECRET'),
'access_token' => getenv('FACEBOOK_ACCESS_TOKEN'),
],
...
```

You will need to create a long-life access token for your Facebook page. You can do so with the [Graph API Explorer](https://developers.facebook.com/tools/explorer). Select your Facebook App, then select a Page Access Token for your page. Next, make sure you have both `manage_pages` and `publish_pages` as permissions - you may be prompted to authorize them.

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](https://developers.facebook.com/tools/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](https://developers.facebook.com/tools/debug/accesstoken) 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](https://developers.facebook.com/tools/debug/accesstoken) to make sure that your token has these scopes : [ manage_pages, publish_pages, public_profile ]
Once you have an access token, copy it into the [Access Token Tool](https://developers.facebook.com/tools/debug/accesstoken) to extend it for a longer period of time so it doesn't expire.

## Usage

Expand All @@ -84,60 +77,62 @@ class NewsWasPublished extends Notification
return [FacebookPosterChannel::class];
}

/**
* Get the Facebook post representation of the notification.
*
* @param mixed $notifiable.
* @return \NotificationChannels\FacebookPoster\FacebookPosterPost
*/
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.

````php
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.
````php
It is possible to publish link with your post too. You just have to pass the URL to the `withLink` method.

```php
public function toFacebookPoster($notifiable) {
return (new FacebookPosterPost('Laravel notifications are awesome!'))->withLink('https://laravel.com');
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.
````php
It is possible to publish image with your post too. You just have to pass the image path to the `withImage` method.

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

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

```

Note that an absolute URL is required.

### 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.
````php
It is also possible to publish video with your post too. You just have to pass the video path to the `withVideo` method.

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

### Publish Facebook scheduled post
It is also possible to publish a scheduled post. You just have to pass a UNIX timestamp to the ``` scheduledFor ``` method.
````php
It is also possible to publish a scheduled post. You just have to pass a UNIX timestamp to the `scheduledFor` method.

```php
public function toFacebookPoster($notifiable) {
return (new FacebookPosterPost('Laravel notifications are awesome!'))
->scheduledFor(1538061702);
->scheduledFor(now()->addWeek());
}
````

```

## Changelog

Expand All @@ -149,10 +144,6 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen
$ composer test
```

## Security

If you discover any security related issues, please email ahmed29329@gmail.com instead of using the issue tracker.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
Expand Down

0 comments on commit 9123382

Please sign in to comment.