推文帖子{{errors“:[{”code“:189,”message“:”创建状态时出错。“}]}

时间:2015-02-24 13:17:31

标签: php json image twitter

我正在尝试使用图片和指向我网站的链接在Twitter上发布推文 我收到以下错误:

{"errors": [{"code": 189, "message": ". Error creating status"}]}

我尝试使用twitter api: 使用update.json 这条推文已发布,但没有图片。 和

update_with_media.json

我收到错误

这是我使用的代码:

require '../tmhOAuth.php';
require '../tmhUtilities.php';
 $tmhOAuth = new tmhOAuth(array(
   'consumer_key'    => 'xxxxxxxxxx',
   'consumer_secret' => 'xxxxxxxxxxxxx',
   'user_token'      => 'xxxxxxxxxxxxxxxxxxxx',
    'user_secret'     => 'xxxxxxxxxxxxxxxxxx',
     ));

       // we're using a hardcoded image path here. You can easily replace                  this with an uploaded image-see images.php example)
      // 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image'] ['type']};filename={$_FILES['image']['name']}",

     $picimg="img.jpg";

     $code = $tmhOAuth->request('POST',             'https://api.twitter.com/1.1/statuses/update_with_media.json',

     array(
      'media[]'  => "@{$picimg}",
      'status'   => "status"
      ),
     true, // use auth
      true  // multipart
      );

  if ($code == 200) {
        tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
   } else {
       tmhUtilities::pr($tmhOAuth->response['response']);
          }

我在谷歌搜索了很多但没有给我任何东西。 我不明白发生了什么

1 个答案:

答案 0 :(得分:0)

图像网址和更多内容都很糟糕。 我在当地做了一个不同api的例子。 我用过API https://github.com/themattharris/tmhOAuth

我还为依赖项安装了composer。 安装依赖项twitter api。

最重要的是: 这段代码:

  $picimg="img.jpg";
  array(
  'media[]'  => "@{$picimg}",
  'status'   => "status"
  )
这是错的。 但上面这个很好

$image = __DIR__.DIRECTORY_SEPARATOR .'..' . DIRECTORY_SEPARATOR . 'fotos'.         DIRECTORY_SEPARATOR . 'foto1.jpg';

使用DIRECTORY_SEPARATOR代替反斜杠,如果错误响应不是189,这非常重要

$name  = basename($image);
$status = "Picture time";
$media = "@{$image};type=image/jpg;filename={$name}";
必须以这种格式很好地表示媒体,而不仅仅是网址字符串。

  // we set the type and filename are set here as well
    $params = array(
   'media[]' => $media,
   'status'  => $status
 );

这是有效的AMIGOS