I'm trying to use larval's queues to post to Facebook , I'm having no luck! my code works fine without using queues, but i need to be able to use the same code with a que.
my initial code to post an image to Facebook looks like this :
try
{
$fb->setDefaultAccessToken($token);
$fb->post('/me/photos', ['url' => cloudinary_url("$photorequest"),'caption' => $body . $userPage]);
}
catch (Facebook\Exceptions\FacebookResponseException $e)
{
// continue to next request;
}
now with me trying to use a que, I did this in my jobs folder:
namespace PMS\Jobs;
use PMS\Jobs\Job;
use Illuminate\Http\Request;
use SammyK\LaravelFacebookSdk\LaravelFacebookSdk;
use Facebook;
use Session;
use PMS\Photo;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class PostToFBwithImage extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
public $fb;
public $token;
public $photorequest;
public $userPage;
public $body;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($token, $photorequest, $userPage, $body)
{
$this->token = $token;
$this->photorequest = $photorequest;
$this->userPage = $userPage;
$this->body = $body;
}
/**
* Execute the job.
*
* @return void
*/
public function handle(LaravelFacebookSdk $fb)
{
try
{
$fb->setDefaultAccessToken($token);
$fb->post('/me/photos', ['url' => cloudinary_url("$photorequest"),'caption' => $body . $userPage]);
}
catch (Facebook\Exceptions\FacebookResponseException $e)
{
// continue to next request;
}
}
}
and calling this in my controller:
$this->dispatch(new PostToFBwithImage($token, $photorequest, $userPage, $body));
I know I'm doing something wrong in my PostToFBwithImage class, I just don't know what?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire