我正在使用matt harris的推特库https://github.com/themattharris/tmhOAuth并按照图片上传示例。
在尝试发布未返回$ tmhOAuth-> response ['response']的图片时,我返回零。
我尝试过的步骤
它的运行速度非常快,这意味着它甚至没有尝试发布图像。
关于为什么这不起作用或我需要在服务器上配置的任何想法
以下是我从示例中复制的代码。
<?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']);
}
?>