如何使用Laravel框架中的thujohn/twitter
库将推文发布到我在twitter.com管理的多个帐户?
答案 0 :(得分:1)
我之前尝试在多个Twitter帐户上发布时遇到了同样的问题,我已经解决了这个问题:
首先:您需要为您管理的每个Twitter帐户创建一个twitter app,并从每个应用程序中获取这些数据:
以下是您将如何使用它们:
// 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