使用库发布图像什么都不返回

时间:2012-11-08 16:09:51

标签: php curl twitter

我正在使用matt harris的推特库https://github.com/themattharris/tmhOAuth并按照图片上传示例。

在尝试发布未返回$ tmhOAuth-> response ['response']的图片时,我返回零。

我尝试过的步骤

  1. 按原样运行示例
  2. 运行验证ssl-正常工作
  3. 运行状态更新但没有按预期正确发布图像
  4. 将网址从1交换到1.1-没有任何变化,库仍然返回零
  5. 它的运行速度非常快,这意味着它甚至没有尝试发布图像。

    关于为什么这不起作用或我需要在服务器上配置的任何想法

    以下是我从示例中复制的代码。

    <?php
    // testing hmac works- correctly
    echo hash_hmac('ripemd160', 'The quick brown fox jumped over the lazy dog.', 'secret');
    
    
    $tmhOAuth = array( 'consumer_key' => 'removed',
                       'consumer_secret' => 'removed',
                       'user_token' => 'removed', 
                       'user_secret' => 'removed');
    
    
    // array(
    //   'consumer_key'    => 'YOUR_CONSUMER_KEY',
    //   'consumer_secret' => 'YOUR_CONSUMER_SECRET',
    //   'user_token'      => 'A_USER_TOKEN',
    //   'user_secret'     => 'A_USER_SECRET',
    // )
    
    require 'tmhOAuth.php';
    require 'tmhUtilities.php';
    $tmhOAuth = new tmhOAuth($tmhOAuth);
    
    // 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 = 'image.png';
    
    $code = $tmhOAuth->request(
      'POST',
      'https://upload.twitter.com/1.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']);
    }
    ?>
    

1 个答案:

答案 0 :(得分:1)

请求中的帖子网址https://upload.twitter.com应为http://api.twitter.com