I use this framework: https://github.com/abraham/twitteroauth
Basically it goes:
$request = new \Abraham\TwitterOAuth\TwitterOAuth(
'consumer_key',
'consumer_secret'
);
$request->setOauthToken(
$post['oauth_token_unserialized']->getToken(),
$post['oauth_token_unserialized']->getTokenSecret()
);
$media = $request->upload('media/upload', [
'media' => $attachment['path']
]);
$mediaIds[] = $media['media_id_str'];
$result = $request->post(
'statuses/update',
[
'status' => 'Your message',
'media_ids' => implode(',', $mediaIds)
]
);
It won’t post the image twice, it just allows you to upload multiple images as up to 4 images can be used per tweet. You can also attach that media id to more than one tweet.