I want to share "image" on twitter with php,In other words i have image and i want whenever any user click on "share" button then image should post of his "Twitter wall", I tried with two different code/method but in both cases...image is posting on my wall (i used credentials(token,secret)with my account), so i want image should post on users(who want to share) instead of my "Twitter wall",How can i do this ? Here is my First code/method which i tried
require_once('src/codebird.php');
$image="index.jpg";
$message="Lorem Ipsum dummy text";
// note: consumerKey, consumerSecret, accessToken, and accessTokenSecret all come from your twitter app at https://apps.twitter.com/
\Codebird\Codebird::setConsumerKey("xxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxx");
$cb = \Codebird\Codebird::getInstance();
$cb->setToken("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$reply = $cb->media_upload(array(
'media' => $image
));
$mediaID = $reply->media_id_string;
$params = array(
'status' => $message,
'media_ids' => $mediaID
);
$reply = $cb->statuses_update($params);
And i tried with another code/method also, Here is my code
require("config.php");
require("vendor/autoload.php");
use Abraham\TwitterOAuth\TwitterOAuth;
$img="index.jpg";
if(isset($_POST['shares'])) {
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$media1 = $connection->upload('media/upload', ['media' => $img]);
$parameters = [
'status' => 'Lorem Ipsum dummy text!',
'media_ids' => implode(',', [$media1->media_id_string])
];
$result = $connection->post('statuses/update', $parameters);
$id=$result->id;
if($id || $id!=="")
{
echo "Image uploaded Successfully on twitter";
}
else
{
echo "Error! Something went wrong";
}
}
?>
<html>
<form action="index.php" method="POST" name="myform">
<input type="hidden" name="shares" value="shares">
<input type="submit" name="submit" id="submit" value="share">
</form>
</html>
