【发布时间】:2016-10-08 22:51:19
【问题描述】:
我正在使用https://github.com/thujohn/twitter 上的 thujohn/twitter 包将用户状态帖子从我的网站更新到 twitter。
我想用larvae的队列在后台发布这个函数。但我一直得到一份失败的工作。出现错误:
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));
如果我在控制器中运行它,我的函数可以正常工作,但如果我尝试将它分派给作业,我的作业会失败
【问题讨论】:
标签: php twitter queue laravel-5.2 twitter-oauth