I am using matt harris’ twitter library https://github.com/themattharris/tmhOAuth and following the image upload example.
I get a zero returned when trying to post an image with no $tmhOAuth->response[‘response’] being returned.
Steps i have tried
- Running the example as it is- fails
- Running verify ssl- works fine
- Running the status update with out the image- it posts correctly as expected
- swapping the url from 1 to 1.1- nothing changes, library still returns zero
It runs quite quickly implying its not even trying to post an image.
Any ideas on why this isnt working or anything i need to configure on the server
Below is the code i copied from the example to try with.
<?php
// testing hmac works- correctly
echo hash_hmac('ripemd160', 'The quick brown fox jumped over the lazy dog.', 'secret');
$tmhOAuth = array( 'consumer_key' => 'removed',
'consumer_secret' => 'removed',
'user_token' => 'removed',
'user_secret' => 'removed');
// array(
// 'consumer_key' => 'YOUR_CONSUMER_KEY',
// 'consumer_secret' => 'YOUR_CONSUMER_SECRET',
// 'user_token' => 'A_USER_TOKEN',
// 'user_secret' => 'A_USER_SECRET',
// )
require 'tmhOAuth.php';
require 'tmhUtilities.php';
$tmhOAuth = new tmhOAuth($tmhOAuth);
// 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.
$image = 'image.png';
$code = $tmhOAuth->request(
'POST',
'https://upload.twitter.com/1.1/statuses/update_with_media.json',
array(
'media[]' => "@{$image};type=image/jpeg;filename={$image}",
'status' => 'Picture time',
),
true, // use auth
true // multipart
);
if ($code == 200) {
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
tmhUtilities::pr($tmhOAuth->response['response']);
}
?>
The post url https://upload.twitter.com in the request should be http://api.twitter.com