如何通过Laravel中的“thujohn / twitter”库将推文发布到多个推特账号?

时间:2016-04-19 22:22:09

标签: php laravel twitter

如何使用Laravel框架中的thujohn/twitter库将推文发布到我在twitter.com管理的多个帐户?

1 个答案:

答案 0 :(得分:1)

我之前尝试在多个Twitter帐户上发布时遇到了同样的问题,我已经解决了这个问题:

首先:您需要为您管理的每个Twitter帐户创建一个twitter app,并从每个应用程序中获取这些数据:

  • API密钥(使用者密钥)
  • API秘密(消费者秘密)
  • 访问令牌
  • 访问令牌密钥

以下是您将如何使用它们:

// set twitter app data of the twitter account you are going to publish to..
if (some_condition) 
{
    $consumer_key = "account_consumer_key";
    $consumer_secret = "account_consumer_secret";
    $access_token = "account_access_token";
    $access_token_secret = "account_access_token_secret";
} 
else if (some_other_condition) 
{
    $consumer_key = "account_consumer_key";
    $consumer_secret = "account_consumer_secret";
    $access_token = "account_access_token";
    $access_token_secret = "account_access_token_secret";
}

// set the new configurations
Twitter::reconfig([
    "consumer_key" => $consumer_key,
    "consumer_secret"  => $consumer_secret,
    "token" => $access_token,
    "secret" => $access_token_secret,
]);

$tweet = [
    'status' => "Some text that doesn't exceed 140 characters",
];

$tweet_result = Twitter::postTweet($tweet);

更多信息和信用转到:Hafsal