Note that there are some explanatory texts on larger screens.

plurals
  1. POUpload image PHP to twitter (api)
    primarykey
    data
    text
    <p>i'm new to PHP, so please keep it simple enough ^^..</p> <p>I try to upload an image to twitter with the api.</p> <p>I can already post an image to twitter (test.jpg), when the file is on my server, but the user has to be able to direct upload it to twitter...</p> <p>How can i do this ?</p> <p>I have this code in 'tweet.html'</p> <pre><code>&lt;form action="photo_tweet.php" method="post"&gt; &lt;p&gt;tweet: &lt;input type="text" name="tweet" /&gt;&lt;/p&gt; &lt;input type="file" name="image" id="image"/&gt; &lt;input type="submit" name="submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>And i have this code in 'photo_tweet.php'</p> <pre><code>&lt;?php /** */ require '../tmhOAuth.php'; require '../tmhUtilities.php'; $tmhOAuth = new tmhOAuth(array( 'consumer_key' =&gt; 'xxxxxxxxxxxxxx', 'consumer_secret' =&gt; 'xxxxxxxxxxxxxx', 'user_token' =&gt; 'xxxxxxxxxxxxxx', 'user_secret' =&gt; 'xxxxxxxxxxxxxx', )); // we're using a hardcoded image path here. You can easily replace this with // an uploaded image - see images.php in the examples folder for how to do this // 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}", // this is the jpeg file to upload. It should be in the same directory as this file. $tweetmessage = $_POST['tweet']; $image = 'test.jpg'; $code = $tmhOAuth-&gt;request( 'POST', 'https://upload.twitter.com/1/statuses/update_with_media.json', array( 'media[]' =&gt; "@{$image};type=image/jpeg;base64;filename={$image}", 'status' =&gt; $tweetmessage , ), true, // use auth true // multipart ); if ($code == 200) { tmhUtilities::pr(json_decode($tmhOAuth-&gt;response['response'])); } else { tmhUtilities::pr($tmhOAuth-&gt;response['response']); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload