Giter Site home page Giter Site logo

laravel-notification-channels / facebook-poster Goto Github PK

View Code? Open in Web Editor NEW
137.0 13.0 28.0 98 KB

Use notifications to create posts on Facebook

Home Page: http://laravel-notification-channels.com

License: MIT License

PHP 100.00%
laravel-notification-channels facebook

facebook-poster's Introduction

FacebookPoster Notification Channel For Laravel

Latest Version on Packagist Software License Build Status StyleCI Total Downloads

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

Contents

Installation

You can install this package via Composer:

composer require laravel-notification-channels/facebook-poster

Configuration

You'll need to get the Facebook Page ID as well as a page access token with the pages_read_engagement and pages_manage_post permissions. You will need to go through App Review in order to use these permissions. Then, add the configuration to your config/services.php file:

...
'facebook_poster' => [
    'page_id' => env('FACEBOOK_PAGE_ID'),
    'access_token' => env('FACEBOOK_ACCESS_TOKEN'),
],

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];
    }

    /**
     * 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!');
    }
}

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 custom configuration

You can implement routeNotificationForFacebookPoster() on your notifiable class in order to provide custom configuration.

public function routeNotificationForFacebookPoster(): array
{
    return [
        'page_id' => 'customPageId',
        'access_token' => 'customAccessToken',
    ];
}

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

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 atymic avatar coroin avatar dwightwatson avatar freekmurze avatar laravel-shift avatar lightwalkernet avatar moleculezz avatar riclep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facebook-poster's Issues

Required "app_id" key (FACEBOOK_APP_ID)

Hi,

I've followed every step but I can't fix this problem.
Required "app_id" key not supplied in the config and could not find fallback environment variable "FACEBOOK_APP_ID"

My .env

FACEBOOK_APP_ID=my_app_id
FACEBOOK_APP_SECRET=my_app_secret
FACEBOOK_ACCESS_TOKEN=my_access_token
My config/services.php

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

The same problem on my end and on a dd(config('services.facebook_poster')) return

^ array:3 [▼
  "app_id" => "447881111111111"
  "app_secret" => "447886111111111|JOf-XpjhoVj6PoX8iFkY_1ym2bY"
  "access_token" => "EAAGXWaqI5dgBADFVPVPcXH60sNruOPyG6xPefTcOpBjTt3GlSUj8eM27pClYgrZCJunhWF4FwIfodiBJHsB5ywyApric2gcH4mPlBh4tygcYOd8oGH5wJ8ZAKKktK61UDXS2H8ZBO5eduKv2ijCko3hXffKPh0Z ▶"
]

but on dd($config) in vendor/facebook/graph-sdk/src/Facebook/Facebook.php return 

^ array:9 [▼
  "app_id" => null
  "app_secret" => null
  "default_graph_version" => "v2.10"
  "enable_beta_mode" => false
  "http_client_handler" => null
  "persistent_data_handler" => null
  "pseudo_random_string_generator" => null
  "url_detection_handler" => null
  "default_access_token" => "EAAGXWaqI5dgBADFVPVPcXH60sNruOPyG6xPefTcOpBjTt3GlSUj8eM27pClYgrZCJunhWF4FwIfodiBJHsB5ywyApric2gcH4mPlBh4tygcYOd8oGH5wJ8ZAKKktK61UDXS2H8ZBO5eduKv2ijCko3hXffKPh0Z ▶"
]

The Response content must be a string or object implementing __toString(), "object" given

Hello Everyone,
please help me to solve issue.

Laravel version = 5.7.19

I getting error wen import Excel.

I have controller like, demoController and code show below,

file); // not working. give error like,The Response content must be a string or object implementing __toString(), "object" given. } public function export_products(Request $request) { $data = $request->all(); return Excel::download(new productExport, 'export_products.xls');//working fine } } Thanking You. ![Error-of-import-excel](https://user-images.githubusercontent.com/46314055/50585207-e669f680-0e99-11e9-8a3b-de3110180413.png)

Post multiple Media and private Images

Hello, I just started using this great package. I have two questions about it.

It doesn't seem to be possible to upload multiple media at the moment, Is there any plan for that feature ?

The current way of uploading seems to require the file to be a public url. I may be mistaken but trying to upload an image located on my server but not in the public folder resulted in an error. Is it a mistake on my side ?

Thanks for the package and Happy new year to you all.

Laravel 5.6

Hi, I see that you added support for Laravel 5.6 in commit 236ce1b.

Could you publish a new package release?

Thank you.

Laravel stuck when exception happen

How can I let Laravel continue even if poster return exception?
I make notification when user register. If facebook poster returns exception for any reason it stops working and not move to the next page.

Code review

Let me know when you're done writing tests and code. I'll do a quick review and setup Packagist and other services

FACEBOOK_APP_ID missing ???

Hello I'm having the following error :
Facebook\Exceptions\FacebookSDKException
Required "app_id" key not supplied in config and could not find fallback environment variable "FACEBOOK_APP_ID"

I 'm having this into my .env file (fakes id & token):

FACEBOOK_APP_ID=YYYYYYYYY
FACEBOOK_APP_SECRET=ZZZZZZZZZ
FACEBOOK_ACCESS_TOKEN=TTTTTTTTTT

And I add this into services.php:

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

I'm using Laravel 7.1 and running with Homestead.
Any idea ? Thanks, Denis

Permision errro

Don't publish

FacebookResponseException in FacebookResponseException.php line 126:
(#200) Requires extended permission: publish_actions

Thanxx

Cannot install it with laravel v5.4.15

Getting the following error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for laravel-notification-channels/facebook-poster ^0.0.1 -> satisfiable by laravel-notification-channels/facebook-poster[0.0.1].
    - Conclusion: remove laravel/framework v5.4.15
    - Conclusion: don't install laravel/framework v5.4.15
    - laravel-notification-channels/facebook-poster 0.0.1 requires illuminate/notifications 5.3.* -> satisfiable by illuminate/notifications[v5.3.0, v5.3.16, v5.3.23, v5.3.4].
    - don't install illuminate/notifications v5.3.0|don't install laravel/framework v5.4.15
    - don't install illuminate/notifications v5.3.16|don't install laravel/framework v5.4.15
    - don't install illuminate/notifications v5.3.23|don't install laravel/framework v5.4.15
    - don't install illuminate/notifications v5.3.4|don't install laravel/framework v5.4.15
    - Installation request for laravel/framework (locked at v5.4.15, required as 5.4.*) -> satisfiable by laravel/framework[v5.4.15].


Installation failed, reverting ./composer.json to its original content.

Graph API v9.0 Deprecation?

Hi, thank you for this awesome package. I just logged into my Facebook developer dashboard and there's a notice: Reminder: Graph API v9.0 will be deprecated on Feb 23, 2023. Please use the API Upgrade Tool to understand how this might impact your app. For more details see the changelog

 $this->guzzle->post("https://graph.facebook.com/v9.0/{$pageId}/feed?access_token={$accessToken}", [
            'form_params' => $post->getBody(),
        ]);

Any chance we can get this upped before then? TIA!

Per user settings

I guess this doesn't class as an issue per se, but, I was trying to implement per user settings, such as the twitter issue below.
https://github.com/laravel-notification-channels/twitter/issues/13
)
I put the following in my notification:

if ($fbSettings = $notifiable->routeNotificationFor('facebookPoster')) {
  $this->switchSettings($fbSettings);
}

and in my model:

    public function routeNotificationForFacebookPoster()
    {
      return [
        $this->facebook_app_id,
        $this->facebook_page_secret,
        $this->facebook_page_token,
      ];
    }

If I dd($fbSettings) it returns the right info.

I found the following format in your code:

 return new \Facebook\Facebook([
                    'app_id' => config('services.facebook_poster.app_id'),
                    'app_secret' => config('services.facebook_poster.app_secret'),
                    'default_access_token' => config('services.facebook_poster.access_token'),
                ]);

So I mimic that in my method

    private function switchSettings($fbSettings)
  {
    $this->facebook = new \Facebook\Facebook(
      ['app_id' => $fbSettings[0],
      'app_secret' => $fbSettings[1],
      'default_access_token' =>$fbSettings[2],
      ]);
  }

Despite all of that, I get:

FacebookSDKException in FacebookRequest.php line 209:
You must provide an access token.

Laravel 5.5

Please When Will You Add Support For Laravel 5.5

Support Laravel 5.8

 - Installation request for laravel-notification-channels/facebook-poster ^1.4 -> satisfiable by laravel-notification-channels/facebook-poster[1.4.0].
    - Conclusion: remove laravel/framework v5.8.2
    - Conclusion: don't install laravel/framework v5.8.2

Unable to install in laravel 5.8.35

Unable to install package on laravel v5.8.35

Problem 1
    - Installation request for laravel-notification-channels/facebook-poster ^4.0 -> satisfiable by laravel-notification-channels/facebook-poster[4.0.0].
    - Conclusion: remove laravel/framework v5.8.35
    - Conclusion: don't install laravel/framework v5.8.35
    - laravel-notification-channels/facebook-poster 4.0.0 requires illuminate/notifications ^8.0 -> satisfiable by illuminate/notifications[8.x-dev, v8.0.0, v8.0.1, v8.0.2, v8.0.3, v8.0.4, v8.1.0, v8.2.0, v8.3.0, v8.4.0, v8.5.0, v8.6.0, v8.7.0, v8.7.1, v8.8.0].
    - don't install illuminate/notifications 8.x-dev|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.0.0|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.0.1|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.0.2|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.0.3|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.0.4|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.1.0|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.2.0|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.3.0|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.4.0|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.5.0|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.6.0|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.7.0|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.7.1|don't install laravel/framework v5.8.35
    - don't install illuminate/notifications v8.8.0|don't install laravel/framework v5.8.35
    - Installation request for laravel/framework (locked at v5.8.35, required as 5.8.*) -> satisfiable by laravel/framework[v5.8.35].

publish_to_groups permission with user token

i am getting error ==>
(#200) If posting to a group, requires app being installed in the group, and \ either publish_to_groups permission with user token, or both manage_pages \ and publish_pages permission with page token; If posting to a page, \ requires both manage_pages and publish_pages as an admin with \ sufficient administrative permission

PHP 8 Support?

What do you think, @dwightwatson?

This seems to be preventing composer from updating for PHP 8 due to composer.json PHP version constraint.

Endpoints out of date

Hello,
I have just installed this package on my laravel build, however the endpoints for posting are out of date and need updating:

(#200) This endpoint is deprecated since the required permission publish_actions is deprecated

This is using the below function:

  public function toFacebookPoster($image)
    {
        return (new FacebookPosterPost($image->description))->withImage(asset('albums/' . $image->album_id . '/' . $image->image));
    }

Please can you update them or tell me how to?

Facebook API Version

Hi,

It looks like the Facebook PHP Graph SDK used by this package defaults to the Facebook Graph API version 2.10 which is being deprecated in under a month. Does this package user a later version? I couldn’t see where it was set, but Facebook’s package should allow setting it.

Thanks.

Endpoint Deprecated.

Hello,
I have just installed this package on my laravel project, when i try to use it i get the below error.

(#200) This endpoint is deprecated since the required permission publish_actions is deprecated

This is using the below function:

  public function toFacebookPoster($listing)
    {
        return (new FacebookPosterPost($listing->title))->withImage(asset('listings/' . $listing->featured_image));
    }

Please can you update them or tell me how to?

Required "app_id" key (FACEBOOK_APP_ID)

Hi,

I've followed every step but I can't fix this problem.
Required "app_id" key not supplied in config and could not find fallback environment variable "FACEBOOK_APP_ID"

My .env

FACEBOOK_APP_ID=my_app_id
FACEBOOK_APP_SECRET=my_app_secret
FACEBOOK_ACCESS_TOKEN=my_access_token

My config/services.php

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

Method notify does not exist.

I am trying to post on Facebook and Twitter when creating an article if a radio box facebook and twitter is ticked.

I also have to get app_id etc from DB since there are 10 centers. And all centers have different facebook accounts.

In ArticleController

use App\Notifications\FacebookPublished;
use App\Notifications\TwitterPublished;

...
...
public function store(StoreRequest $request)
{
    $center = Center::where('id', $request->center_id)->first();
    //dd($request->title); // shows title 
    if($request->input('facebook'))
    {
        config(['app_id' => $center->facebook_app_id]); 
        config(['app_secret' => $center->facebook_app_secret]); 
        config(['access_token' => $center->facebook_access_token]); 
        // using $request
        $request->notify(new FacebookPublished());
    }
    if($request->input('twitter'))
    {
        config(['consumer_key' => $center->twitter_consumer_key]);
        config(['consumer_secret' => $center->twitter_consumer_secret]);
        config(['acess_token' => $center->twitter_access_token]);
        config(['access_secret' => $center->twitter_access_secret]);
        $request->notify(new TwitterPublished());
    }
    ...
    ...
}

In App/Notifications/FacebookPublished,

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\FacebookPoster\FacebookPosterChannel;
use NotificationChannels\FacebookPoster\FacebookPosterPost;

class FacebookPublished extends Notification
{
    public function via($notifiable)
    {
        return [FacebookPosterChannel::class];
    }

    public function toFacebookPoster($notifiable) {
        return (new FacebookPosterPost($request->title .' '.$request->content))->withImage($request->thumb);
    }
}

Article model:

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Backpack\NewsCRUD\app\Models\Article as OriginalArticleModel;

class Article extends OriginalArticleModel
{
    use Notifiable;

    protected $fillable = ['slug', 'title', 'content', 'center_id', 'image','thumb', 'status', 'lightbox_folder','category_id', 'featured', 'date'];

}

When I store, I get an error;

BadMethodCallException in Macroable.php line 74: Method notify does not exist.

What am I doing wrong here?

Error posting to page

Hello, I have used this package before for posting on facebook but recently I stumble upon this error.

Facebook\Exceptions\FacebookAuthorizationException: (#200) This endpoint is deprecated since the required permission publish_actions is deprecated in (project_path)/vendor/facebook/graph-sdk/src/Facebook/Exceptions/FacebookResponseException.php:137

Can you help me ? here is my notification code

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Storage;
use NotificationChannels\FacebookPoster\FacebookPosterChannel;
use NotificationChannels\FacebookPoster\FacebookPosterPost;

class FacebookPostNotification extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->queue = 'notifications';
    }

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

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->line('The introduction to the notification.')
            ->action('Notification Action', url('/'))
            ->line('Thank you for using our application!');
    }

    public function toFacebookPoster($notifiable)
    {
        return (new FacebookPosterPost('Post With Image https://laravel.com'))
            ->withImage('https://picsum.photos/id/237/200/300');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ';'

Hi,

This is my code

public function toFacebookPoster($post) {
        return new FacebookPosterPost($post->title)->withImage(url('storage/images/'.$post->image))->withLink('https://domaindddd.com/blog/'.$post->slug);
    }

when I publish new post I get

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ';'

On

return new FacebookPosterPost($post->title)->withImage(url('storage/images/'.$post->image))->withLink('https://domaindddd.com/blog/'.$post->slug);

any idea?

Calling Wrong Access Token?

Hi There,

I've updated my access token as the last open expired but FacebookPosterPost is still calling the older access token. I've cleared all my caches over and over again. I'm not sure what else to do?

Client error: `POST https://graph.facebook.com/v9.0/ID/feed?access_token=Token` resulted in a `403 Forbidden` response:
{"error":{"message":"(#200) If posting to a group, requires app being installed in the group, and \\\n          either p (truncated...)

The new access token has the right permissions, if only it would let me change it.

The Response content must be a string or object

Hi,
I'm trying to post something to my facebook page, but it doesn't work.
code:

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

Error:
The Response content must be a string or object implementing __toString(), "object" given.

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.