我正在使用来自https://github.com/themattharris/tmhOAuth的tmhOAuth,并尝试将图片从我的网站上传到用户的Twitter页面。 callback.php上的响应为200(成功),但用户页面上没有任何内容。该应用程序具有r / w权限,并且"允许此应用程序用于使用Twitter登录"检查。有人有想法吗?我正在使用2个PHP文件:
twitter.php
include("tmhOAuth.php");
include("tmhUtilities.php");
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'abcd123',
'consumer_secret' => 'xyz',
'curl_ssl_verifypeer' => false
));
$tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''));
$response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
$temp_token = $response['oauth_token'];
$temp_secret = $response['oauth_token_secret'];
$time = $_SERVER['REQUEST_TIME'];
setcookie("Temp_Token", $temp_token, $time + 3600 * 30, '/');
setcookie("Temp_Secret", $temp_secret, $time + 3600 * 30, '/');
setcookie("Tweet_Txt", 'Share your AFA stand!', $time + 3600 * 30, '/');
setcookie("Img_Url", 'success', $time + 3600 * 30, '/');
$url = $tmhOAuth->url("oauth/authorize", "") . '?oauth_token=' . $temp_token;
echo '<a href="'.$url.'">Post this image on Twitter</a>';
callback.php
define("CONSUMER_KEY", "abcd123");
define("CONSUMER_SECRET", "xyz");
include("tmhOAuth.php");
include("tmhUtilities.php");
$token = $_COOKIE['Temp_Token'];
$secret = $_COOKIE['Temp_Secret'];
$txt = $_COOKIE['Tweet_Txt'];
$img = base64_encode(file_get_contents('wide/achievement.jpg'));
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => CONSUMER_KEY,
'consumer_secret' => CONSUMER_SECRET,
'user_token' => $token,
'user_secret' => $secret,
'curl_ssl_verifypeer' => false
));
$tmhOAuth->request("POST", $tmhOAuth->url("oauth/access_token", ""), array(
'oauth_verifier' => $_GET["oauth_verifier"]
));
$response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
$tmhOAuth->config["user_token"] = $response['oauth_token'];
$tmhOAuth->config["user_secret"] = $response['oauth_token_secret'];
$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1.1/media/upload.json',
array(
'media_data' => $img,
'status' => $txt
),
true, // use auth
true // multipart
);
if ($code == 200){
echo '<h1>Your image tweet has been sent successfully</h1>';
}else{
echo $code;
echo "failed<br />";
tmhUtilities::pr($tmhOAuth->response['response']);
}
我收到了#34;您的图片推文已成功发送&#34;,但实际上并未发布。请帮忙。