A
A
Alexey Poloz2017-02-10 01:13:54
PHP
Alexey Poloz, 2017-02-10 01:13:54

How to tweet with images in php using OAuth?

There is this code:

require_once "twitter/twitteroauth.php";

$CONSUMER_KEY = "нанана";
$CONSUMER_SECRET = "нанана";
$OAUTH_TOKEN = "нанана";
$OAUTH_SECRET = "нанана";

$connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET, $OAUTH_TOKEN, $OAUTH_SECRET);
$content = $connection->get('account/verify_credentials');

$quote='123';
$image='http://www.niceseo.ru/wp-content/uploads/2013/07/niceseotwitterapi11tweetwithphotodemoscript.jpg';

$connection->post('statuses/update ', array('status' => $quote));
print 'Размещена запись: "'.$quote.'"';

(regular posts without pictures are fasting)
What and where to add so that this picture is added to the post ????
Maybe I have the wrong / outdated library?
I tried like this: (nothing is fasting and no last message is displayed)
$name = basename($image);
$connection->user_request(array('method' => 'POST','url' => $connection->url('1.1/statuses/update_with_media'),'params' => array('media[]'  => "@{$image};type=image/jpeg;filename={$name}",'status' => $quote,),'multipart' => true,));

From www.niceseo.ru/postim-v-tvitter-s-kartinkoy-na-php...
Tried removing extra commas
Tried like this: (page doesn't even open)
$tmhOAuth = new tmhOAuth(array(
       'consumer_key'    => $network_array['consumer_key'], 
       'consumer_secret' => $network_array['consumer_secret'],
       'user_token'      => $network_array['user_token'],
       'user_secret'     => $network_array['user_secret']
      ));

       $params = array(
      'media[]' => '@' . $process_image['image_path'],  //PATH TO IMAGE
      'status' => $tweet_response,  //THIS IS THE TEXT WE USE FOR THE TWEET
      'in_reply_to_status_id' => $mentions[$c]["id"]  //IF REPLYING, IT'S HERE
       );

       $code = $tmhOAuth->user_request(array(
      'method' => 'POST',
      'url' => $tmhOAuth->url("1.1/statuses/update_with_media"),
      'params' => $params,
      'multipart' => true
       ));

Doesn't work either: (page not loading)
$name = basename($image);

$code = $connection->request(
'POST',
$connection->url('1.1/statuses/update_with_media'),
array(
'media[]' => "@{$image};type=image/jpeg;filename={$name}",
'status' => 'Picture time',
),
true,
true
);

From https://forums.digitalpoint.com/threads/twitter-ap...
Tried like this: (picture doesn't add or doesn't fast at all)
$connection->post('statuses/update_with_media', array('media[]'  => "@{$image};type=image/jpeg;filename={$name}",'status' => $quote));

With build-up: (no longer works)
$connection->post('statuses/update_with_media', array('media[]'  => "@{$image};type=image/jpeg;filename={$name}",'status' => $quote),,'multipart' => true);

And downloaded the full examples: www.niceseo.ru/wp-content/uploads/2013/07/niceseot...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question