自分のウェブサイトで自分の投稿をツイートとして共有したいユーザーの名前で、Twitter にツイートを投稿できるようにしたいと考えています。James Mallison のすばらしい TwitterAPIExchange クラスを使用しており、PHP を使用して Twitter に投稿しようとしています。クラスはここにあります。
私は次の方法でそれを使用しようとしています:
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => $core->getOauthAccessToken(),
'oauth_access_token_secret' => $core->getOauthAccessTokenSecret(),
'consumer_key' => $core->getTwitterConsumerKey(),
'consumer_secret' => $core->getTwitterConsumerSecret()
);
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = 'POST';
$stripped_question = "See my reply to \"$stripped_question\"";
$stripped_response = $stripped_response;
$message = $stripped_question.$stripped_response;
/*$postfields = array(
'status' => rawurlencode(rawurlencode($message))
);*/
$postfields = array(
CURLOPT_HTTPHEADER => array("https://api.twitter.com/oauth/authorize"),
CURLOPT_HEADER => false,
CURLOPT_URL => $core->getHomeUrl(),
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => 'status=' . rawurlencode(rawurlencode($status)),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true,
CURLOPT_SSL_VERIFYPEER => false
);
/** Perform the request and echo the response **/
$twitter = new TwitterAPIExchange($settings);
echo "<!--".var_dump($twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest())."-->";
ただし、何かが間違っているため、次のエラーが表示されます。
string(63) "{"errors":[{"message":"Could not authenticate you","code":32}]}"
それで、私の質問は次のとおりです。私のウェブサイトのユーザーの名前でツイートをツイッターに投稿するにはどうすればよいですか? Twitter がユーザーを認証できないのはなぜですか? データを確認したところ、すべてが正しいようです。問題は投稿の 2 番目のコードにあると思います。答えてくれてありがとう。