如何在twitter中使用API或JAVASCRIPT发布tweet(描述和图像)


How to post tweet (description and images) in twitter using API or JAVASCRIPT

我想使用twitter API或JavaScript发布描述和图像,所以代码是什么…请帮助或任何解决方案。

我使用了以下代码:

include('tmhOAuth.php');
include('tmhUtilities.php');
$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => '2gfF75xRSwnJDgfuwXBUGj59kA',
  'consumer_secret' => 'snGgVlYdVfgOeTVl8aQYG5BQRyEbgxqfgu9B9zTpRomIUh58',
  'user_token'      => '148xf1479562-RYq76XIfgogfhjttdu0kLlWwQwEfgEM8wlRDMX44rUFPP',
  'user_secret'     => 'I7saxfu751zzMnWChgffA0VAiRQIdf2JFwTMLragf6MK4aF8pjbg',
));
  $image = 'Chrysanthemum.jpg';
  $code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
  array(
    'media[]'  => "@{$image}",
        "status"   => "Is this working now?"
       ),
       true, // use auth
       true  // multipart
  );
  if ($code == 200) {
    tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
  } else {
    tmhUtilities::pr($tmhOAuth->response['response']);
  }

但是,我得到了这个错误:JSON响应:

{
errors: [
    {
        message: "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.",
        code: 68
    }
 ]
}

我想你应该使用1.1 APIhttp://dev.twitter.com/blog/api-v1-is-retired

https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media

Resource URL
https://api.twitter.com/1.1/statuses/update_with_media.json