【问题标题】:Laravel queue with Twitter apiLaravel 队列与 Twitter api
【发布时间】: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


    【解决方案1】:

    在这篇博文之后,我设法通过切换到不同的库来解决这个问题:http://markusos.github.io/engage/2014/12/06/1000-tweets-per-week.html

    【讨论】:

      猜你喜欢
      • 2021-09-08
      • 2022-11-11
      • 2020-12-13
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      • 2015-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多