如何使用 PHP 从我的网站推特图像? [英] How to tweet an image using PHP from my website?
问题描述
我正在尝试使用 php 发送图像.我已经阅读了文档并遵循了一些教程.我发送消息时没有任何问题;但是,它不适用于图像.我找不到我的错误在哪里,有人可以帮忙吗??我会深深地感激它.
I am trying to tweet an image using php. I have read the documentation and followed a some tutorials. I don't have any problem when sending a message; however, it does not work with images. I can not find where my mistake is, can anyone help?? I would deeply appreciate it.
<?php
$comments = $_POST['comment'];
if (isset($_POST['Twitter']))
{
require_once('twitter/codebird-php/src/codebird.php');
\Codebird\Codebird::setConsumerKey("xxxxxx","xxxxxx");
$cb = \Codebird\Codebird::getInstance();
$cb->setToken("xxxxxx", "xxxxxxxxxx");
$params = array(
'status' => $comments,
'media[]' => "/images/image1.jpg"
);
$reply = $cb->statuses_update($params);
echo "You have posted your message succesfully";
}
else{
echo "You havent posted anythingh";
}
?>
推荐答案
您需要为 Twitter 提供图像的完全限定 URI.
You need to supply Twitter the fully qualified URI to your image.
您有以下代码:
$params = array(
'status' => $comments,
'media[]' => "/images/image1.jpg"
);
不幸的是,这不是图像的完整 URL,而是一个相对 URL.相反,您需要提供类似以下内容的内容:
Unfortunately, that's not a complete URL to an image, it's a relative URL. Instead, you need to provide something along the lines of this:
$params = array(
'status' => $comments,
'media[]' => "http://www.example.com/images/image1.jpg"
);
此外,根据 Twitter API v1 文档,你需要使用 statuses/update_with_media
而不是 statuses/update
.
In addition, according to the Twitter API v1 documentation, you need to use statuses/update_with_media
instead of statuses/update
.
如果您使用 Twitter API v1,Twitter 还建议使用 v1.1 代替.
If you are using Twitter API v1, Twitter also recommends using v1.1 instead.
这篇关于如何使用 PHP 从我的网站推特图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!