I've got the following working code, the code simply posts a status and an image om my twitter page.
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "xxx",
'oauth_access_token_secret' => "xxx",
'consumer_key' => "xxx",
'consumer_secret' => "xxx"
);
$url = "https://api.twitter.com/1.1/statuses/update_with_media.json";
$requestMethod = "POST";
$tweetmsg = $_POST['post_text'];
$twimage = "Images/twitter-icon.png";
$postfields = array(
'status' => $tweetmsg,
'media[]' => "@{$twimage}"
);
try {
$twitter = new TwitterAPIExchange($settings);
$twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
echo "Success, you just tweeted!";
} catch (Exception $ex) {
echo $ex->getMessage();
}
}
The image is right now placed in a folder (Images) which is in my project. I want the user to able to pick an image from his own computer, write a decription and then tweet it. I've got the following simple HTML form for the posting:
<form method="post" action="index.php">
<textarea id="post_text" name="post_text" type="text"></textarea>
<input type="file" name="post_file" id="post_file" multiple accept="image/*" value="Choose a file"/>
<button type="submit" id="btn_submit">Submit</button>
</from>
So do you guys have any tips or guides which could help me solve my problem? Am i thinking in the right way or should I maybe tackle the problem in another way? Thanks!