2016-10-05 20 views
2

我想用幼虫的队列发布到Facebook,我没有运气!我的代码工作正常,不用队列,但我需要能够使用相同的代码与一个队列。Laravel队列并发布到Facebook

我得到这个例外,在我失败的作业表:现在

try { 
    $fb->setDefaultAccessToken($token); 
    $fb->post('/me/photos', [ 
     'url' => cloudinary_url("$photorequest"), 
     'caption' => $body . $userPage 
    ]); 
} catch (Facebook\Exceptions\FacebookResponseException $e) { 
    // continue to next request; 
} 

我试图用一个:

exception 'Exception' with message '[220] Your credentials do not allow access to this resource.' in /home/vagrant/sites/pms/vendor/thujohn/twitter/src/Thujohn/Twitter/Twitter.php:297 

我最初的代码发布至Facebook的图像看起来是这样的阙,我做这在我的工作文件夹:

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

,并在我的控制器调用此:

$this->dispatch(new PostToFBwithImage($token, $photorequest, $userPage, $body)); 

我知道我在我的PostToFBwithImage类中做错了什么,我只是不知道是什么?

+0

你在使用什么队列驱动程序?这种代码不工作的方式是什么?你有什么错误吗? – Aron

回答

0

不应该在该

$fb->setDefaultAccessToken($token); 
$fb->post('/me/photos', ['url' => cloudinary_url("$photorequest"),'caption' => $body . $userPage]); 

是这样

$fb->setDefaultAccessToken($this->token); 
$fb->post('/me/photos', ['url' => cloudinary_url($this->photorequest), 'caption' => $this->body . $this->userPage]); 

此外,你是否确定在创建作​​业时将正确的值传递给构造函数?