Issues uploading photos through API


#1

Hi all,

I am simply trying to upload and attach an image to a tweet using update with media and keep running in to the same error

‘{“errors”:[{“message”:“Sorry, that page does not exist”,“code”:34}]}’ (length=68)

I have tried several solutions online but can’t seem to crack it as I thought the process was quite simple. Sorry If I’m missing something obvious but any light you could shed on this would be awesome.

Code:
require(“twitteroauth/twitteroauth.php”);
session_start();

$twitteroauth = new TwitterOAuth(‘XXXXXXXXXXXXXXXX’, ‘XXXXXXXXXXXXXXX’, $_SESSION[‘oauth_token’], $_SESSION[‘oauth_token_secret’]);

$image = ‘image.jpeg’;

echo ‘Test’;

$code = $twitteroauth->oAuthRequest(
‘POST’,
https://upload.twitter.com/1/statuses/update_with_media.json’,
array(
‘media[]’ => “@{$image};type=image/jpeg;filename={$image}”,
‘status’ => ‘Standard Tweet’,
),
true, // use auth
true // multipart
);

echo ‘Test’;

var_dump($code);

if ($code == 200) {
json_decode($twitteroauth->response[‘response’]);
} else {
($twitteroauth->response[‘response’]);
echo “try again”;
}


#2

Strange, I verified that that endpoint works:

POST /1/statuses/update_with_media.json HTTP/1.1 Host: upload.twitter.com User-Agent: Go http package Content-Length: 15532 Authorization: OAuth .... Content-Type: multipart/form-data;boundary=963654e642a5c7439585cc4ee13bc65de98b85baa95ce1483914091701c5 Accept-Encoding: gzip

–963654e642a5c7439585cc4ee13bc65de98b85baa95ce1483914091701c5
Content-Disposition: form-data; name=“status”

Hello 2012-10-12 13:43:25.580104 -0700 PDT!
–963654e642a5c7439585cc4ee13bc65de98b85baa95ce1483914091701c5
Content-Disposition: form-data; name=“media[]”; filename="media.png"
Content-Type: application/octet-stream

It does look like the signature for oAuthRequest is
function oAuthRequest($url, $method, $parameters) {
https://github.com/abraham/twitteroauth/blob/master/twitteroauth/twitteroauth.php#L178

Perhaps that’s the issue?


#3