【问题标题】:twitter api v1.1 statuses/update_with_media Missing or invalid url parametertwitter api v1.1 statuses/update_with_media 缺少或无效的 url 参数
【发布时间】:2014-01-06 07:58:46
【问题描述】:

请帮助我,我在使用 api v1.1 将图像上传到 Twitter 时遇到问题 一个月前它工作得很好,但现在不行了。 我正在使用亚伯拉罕 twitteroauth https://github.com/abraham/twitteroauth 我使用 enctype="multipart/form-data" 作为表单标签中的属性 这是我的代码:

             require 'inc/twitter.class.php';   

             if(!empty($_FILES['media']['name'])){    // tweet with media
                  $file_name  = $_FILES['media']['name'];
                  $file_type  = $_FILES['media']['type'];
                  $file_size  = $_FILES['media']['size'];
                  $file_temp  = $_FILES['media']['tmp_name'];
                  $file_error = $_FILES['media']['error'];

                  $handle    = fopen($file_temp,'rb');
                  $image     = fread($handle,filesize($file_temp));
                  fclose($handle);
                  $tweet = new TwitterOAuth($YOUR_CONSUMER_KEY, $YOUR_CONSUMER_SECRET, $row_user_info['access_token_oauth_token'], $row_user_info['access_token_oauth_token_secret']);
                  $result = $tweet->post('statuses/update_with_media',array('media[]' => "@{$image};type={$file_type};filename={$file_temp}",'status' => 'test'));

                  echo '<pre>';
                  print_r($result);
                  echo '</pre>';

结果是:

stdClass Object
(
[errors] => Array
    (
        [0] => stdClass Object
            (
                [code] => 195
                [message] => Missing or invalid url parameter.
            )

    )
)

我不知道其中缺少什么 请帮帮我

【问题讨论】:

  • 请帮我,我需要它

标签: twitter twitter-oauth


【解决方案1】:

Abraham twitteroauth 存在与通过媒体发送推文有关的问题。你可以在这里找到固定版本的 Twitteroauth:

https://github.com/tomi-heiskanen/twitteroauth/blob/77795ff40e4ec914bab4604e7063fa70a27077d4/twitteroauth/twitteroauth.php

使用这个库你必须调用:

$result = $tweet->post('statuses/update_with_media',array('media[]' => "@{$image};type={$file_type};filename={$file_temp}",'status' => 'test'), true);

最后一个参数true表示你正在发送多部分请求。

【讨论】:

  • 我像你说的那样给出错误警告:curl_setopt() [function.curl-setopt]:无法访问 /home/toptwet/public_html/inc/twitter.class 中的����。 php 在函数 http 第 1094 行中的第 1094 行是这一行 curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
  • 您是否包含了最新版本的 twitteroauth?或者您尝试访问的文件路径已更改?
【解决方案2】:

这对我有用

---html---

<form action="" method="POST" enctype="multipart/form-data">
    <div>
      <label for="status">Tweet Text</label>
      <textarea type="text" name="status" rows="5" cols="60"></textarea>
      <br />

      <label for="image">Photo</label>
      <input type="file" name="image" />
      <br />
      <input type="submit" value="Submit" />
    </div>
  </form> 

---php---

if (!empty($_FILES)) {
      // we set the type and filename are set here as well
      $params = array(
        'media[]' => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
        'status'  => $_POST['status']
      );

      $dd = $twitteroauth->post('statuses/update_with_media',$params,true);

      var_dump($dd);
}

使用这个修改后的库

https://github.com/tomi-heiskanen/twitteroauth/blob/77795ff40e4ec914bab4604e7063fa70a27077d4/twitteroauth/twitteroauth.php

【讨论】:

  • 好的,我还有一个问题,我不知道有时你会遇到这个问题>
  • 这个修改后的库为我节省了很多时间,谢谢!
【解决方案3】:

非常感谢,但我编辑了代码,现在可以正常工作了

if (!empty($_FILES)) {
    // we set the type and filename are set here as well
                    $handle    = fopen($_FILES['image']['tmp_name'],'rb');
                    $image     = fread($handle,filesize($_FILES['image']['tmp_name']));
                    fclose($handle);
    $params = array(
      'media[]' => "@{$image};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
      'status'  => $_POST['status']
    );
    $twitteroauth = new TwitterOAuth($YOUR_CONSUMER_KEY, $YOUR_CONSUMER_SECRET, $row_user_info['access_token_oauth_token'], $row_user_info['access_token_oauth_token_secret']);
    $dd = $twitteroauth->post('statuses/update_with_media',$params,true);

    var_dump($dd);

}

【讨论】:

    猜你喜欢
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多