Posting image + status with the Twitter API using php
<p>I ended up using codebird and not TwitterAPIExchange.php. Please see my answer.</p>

<p><a href="https://github.com/J7mbo/twitter-api-php/blob/master/TwitterAPIExchange.php" rel="nofollow noreferrer">TwitterAPIExchange.php</a></p>

<p>I am racking my brain trying to figure out why my code is not working. I am able to post a status update fine to twitter but when I try and add an image it seems to never post it with the status.</p>

<p>With the many <a href="https://stackoverflow.com/questions/24550473/post-status-image-with-twitterapiexchange-on-twitter">posts</a> about this I have read I have tried them all applying the media examples and none seem to work.</p>

<p>One thing is that many of these posts refer to the API call url being <code>https://api.twitter.com/1.1/statuses/update_with_media.json</code> which according to <a href="https://dev.twitter.com/rest/reference/post/statuses/update_with_media" rel="nofollow noreferrer">this article</a> is depreciated.</p>

<p>The new URL "I think" is just <code>https://api.twitter.com/1.1/statuses/update.json</code></p>

<p>At this point the status uploads fine, the image never does. Can anyone help me with my code please.</p>

<pre><code>require_once('TwitterAPIExchange.php');

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' =&gt; "***",
    'oauth_access_token_secret' =&gt; "***",
    'consumer_key' =&gt; "***",
    'consumer_secret' =&gt; "***"
);
$url = "https://api.twitter.com/1.1/statuses/update.json";

$requestMethod = 'POST'; 

$twimage = '60001276.jpg';

$postfields = array(
    'media[]' =&gt; "@{$twimage}",
    'status' =&gt; 'Testing Twitter app'
);

$twitter = new TwitterAPIExchange($settings);

$response = $twitter-&gt;buildOauth($url, $requestMethod)
                   -&gt;setPostfields($postfields)
                   -&gt;performRequest();

print_r($response);
</code></pre>