I am very very new to twitter api, today i first time signup for twitter api in my life. my aim is to post pictures from my website with a message on twitter. I have download its current library from internet, it gives me following 2 files and some examples.
i have include those two files and get this code photo_tweet.php means tweet with photo
here is my code
<?php
require 'tmhOAuth.php';
require 'tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'ZlhOWeCWG2MS5Wxxxxxx',
'consumer_secret' => 'DIPjoKcIWjpGWmw5jGJSKGAOLxxxxxx',
'user_token' => 'xxxxx-OGtPyRSUOUaR6XQRLAFVuv14xxxxxx',
'user_secret' => 'xxxxxoimsrNFhlz7mPa9h5pyVSjxxxxxxx',
));
// 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 = 'a.jpg';
$code = $tmhOAuth->request(
'POST',
'https://upload.twitter.com/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']);
}
?>
a.jpg is on my server.
here is my settings on twitter!
Request type: GET Request URI:* https://api.twitter.com/1/
when I upload all this code and access my code it returns blank scree, when i echo $code; it returns 0
its all what i have observed and experienced. I am in need of your Kind help. I shall be very very thank full to you
Note: Event When I removed my consumer key and consumer secret this code does not show any error. just a blank screen. I want this to show errors in case of any problem but no error
Here is the code for status only it work for me
$consumerKey = $consumer_key;
$consumerSecret = $consumer_secret;
$OAuthToken = $user_token;
$OAuthSecret = $user_secret;
include "OAuth.php";
include "twitteroauth.php";
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret);
$image = 'a.jpg';
$optsArray['status'] = 'Hi';
if (isset($_GET['msg'])) {
$tweetmsg = $_GET['msg'];
$tweet->post('statuses/update',$optsArray);
if($tweet)
echo "Your message has been sent to Twitter.";
else
echo "Your message has not been sent to Twitter.";
} else {
echo "Your message has not been sent to Twitter.";
}
but it post only status when i use
update_with_media.json
and
$optsArray['@media[]'] = "@{$image}";
it does not work , please help me to figure out this issue