我正在为一个应用程序使用Twitpic API。我有点卡住了,因为我似乎找不到错误所在。我读过的所有文档都说这段代码是正确的。如果能帮上忙,我们将不胜感激。谢谢!
function do_twitpic()
{
$media = 'http://image-to-upload.jpg';
$username = $_POST['username'];
$password = $_POST['password'];
$postfields = array();
$postfields['username'] = $username;
$postfields['password'] = $password;
$postfields['media'] = "@".$media;
$twitter_url = 'http://twitpic.com/api/upload';
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $twitter_url);
curl_setopt($curl, CURLOPT_POST, 3);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($curl);
curl_close($curl);
$login_xml = new SimpleXMLElement($result);
if (isset($login_xml->error)) {
print_r($login_xml);
} else {
print_r($login_xml);
}
}非常感谢!
发布于 2011-03-08 23:36:18
根据这个页面,$media需要是图像的二进制编码数据,而不是它的网址。http://www.twitpic.com/api.do#upload
发布于 2012-03-21 07:10:29
图像“实际路径”前面的@,而不是公共URL,会动态地将图像转换为二进制数据。
https://stackoverflow.com/questions/5229544
复制相似问题