0

我正在使用 matt harris 的 twitter 库https://github.com/themattharris/tmhOAuth并遵循图像上传示例。

尝试发布没有返回 $tmhOAuth->response['response'] 的图像时,我得到一个零返回。

我尝试过的步骤

  1. 按原样运行示例 - 失败
  2. 运行验证 ssl- 工作正常
  3. 在没有图像的情况下运行状态更新 - 它按预期正确发布
  4. 将 url 从 1 交换到 1.1-没有任何变化,库仍然返回零

它运行得很快,这意味着它甚至没有尝试发布图像。

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

下面是我从示例中复制的代码以尝试使用。

<?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']);
}
?>
4

1 回答 1

1

请求中的 post url https://upload.twitter.com应该是http://api.twitter.com

于 2012-11-13T18:09:56.453 回答