我正在尝试在Twitter上发布状态和图像。它是扭曲状态但不会扭曲图像。
我推特的PHP代码是
<?php
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config-sample.php');
if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
$_SESSION['oauth_status'] = 'oldtoken';
header('Location: ./clearsessions.php');
}
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['access_token'] = $access_token;
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
if (200 == $connection->http_code) {
$_SESSION['status'] = 'verified';
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
$content = $connection->get('account/verify_credentials');
$image='abc.jpg';
$image1=file_get_contents($image);
$array_disp[0]=$image;
$connection->post('statuses/update',array('status' =>'hello123', 'media[]'=>$image1));
$response=$connection->response['response'];
} else {
header('Location: ./clearsessions.php');
}
现在,如何使用媒体发布上传图片?
答案 0 :(得分:0)
我猜你正在使用Abraham's
库。它不适用于upload_with_media
。以下是他对这个问题的陈述
TwitterOAuth does not currently support media uploads. I hope to add support in the future
替代方法只是从此library下载twitteroauth
文件夹,并将其作为twitteroauth1
粘贴到您的项目中。现在,当您打算使用媒体发推文时,请致电require_once('twitteroauth1/twitteroauth.php');
。
(或)
您只需复制我们已下载的twitteroauth
目录,并将其替换为您的项目。现在,您的代码应该是require_once('twitteroauth/twitteroauth.php');
,因为我们替换了目录。这应该工作!
<?php
session_start();
require_once('twitteroauth1/twitteroauth.php');
require_once('config-sample.php');
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
header('Location: ./clearsessions.php');
}
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,$_SESSION['access_token'] ['oauth_token'], $_SESSION['access_token']['oauth_token_secret']);
$image='abc.jpg';
$content = $connection->get('account/verify_credentials');
$params = array('media[]' => "@{$image}", 'status' => "Testing upload");
$connection->post('statuses/update_with_media', $params,true);
echo "Picture has uploades successfully";
?>