Php 使用twitterapi的Laravel队列
我正在使用上的thujohn/twitter包将用户状态帖子从我的站点更新到twitter 我想使用用户的队列在后台发布此函数。但我一直得到一份失败的工作。有一个错误:Php 使用twitterapi的Laravel队列,php,twitter,queue,laravel-5.2,twitter-oauth,Php,Twitter,Queue,Laravel 5.2,Twitter Oauth,我正在使用上的thujohn/twitter包将用户状态帖子从我的站点更新到twitter 我想使用用户的队列在后台发布此函数。但我一直得到一份失败的工作。有一个错误: exception 'Exception' with message '[220] Your credentials do not allow access to this resource.' in /home/vagrant/sites/pms/vendor/thujohn/twitter/src/Thujohn/Twitt
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
堆栈跟踪:
我的工作是这样的:
namespace PMS\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Twitter;
use Session;
use Illuminate\Http\Request;
class PostToTwitter implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $tweetLength;
public $userPage;
public $body;
//public $twitterToken;
//public $secret;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($tweetLength, $userPage, $body)
{
$this->tweetLength = $tweetLength;
$this->userpage = $userPage;
$this->body = $body;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Twitter::postTweet(['status' => str_limit($this->body . $this->userpage,$this->tweetLength), 'format' => 'json']);
}
}
$this->dispatch(new PostToTwitter($tweetLength, $userPage, $body));
在我的控制器中,我这样调度:
namespace PMS\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Twitter;
use Session;
use Illuminate\Http\Request;
class PostToTwitter implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $tweetLength;
public $userPage;
public $body;
//public $twitterToken;
//public $secret;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($tweetLength, $userPage, $body)
{
$this->tweetLength = $tweetLength;
$this->userpage = $userPage;
$this->body = $body;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Twitter::postTweet(['status' => str_limit($this->body . $this->userpage,$this->tweetLength), 'format' => 'json']);
}
}
$this->dispatch(new PostToTwitter($tweetLength, $userPage, $body));
如果我在控制器中运行我的函数,它可以正常工作,但如果我尝试将其分派到作业,作业会失败我通过切换到其他库来解决此问题,如下博客文章: