【发布时间】:2022-01-08 20:06:58
【问题描述】:
我有一个推送推文的命令,使用 1.1 版本的 twitter API。
它一直在工作,但最近(不完全确定是什么时候)停止在 Twitter 上发布图片。
通过大量调试,似乎根本没有任何错误,只是提要中没有图像。
这可能是由于 api 的新 v2 发生了变化吗? 是否已弃用此功能?
public function send($message, $media = null, $options = [])
{
$mediaIds = [];
foreach ((array) $media as $item) {
$res = $this->request(
'https://upload.twitter.com/1.1/media/upload.json',
'POST',
null,
['media' => $item]
);
$mediaIds[] = $res->media_id_string;
}
return $this->request(
'statuses/update',
'POST',
$options + ['status' => $message, 'media_ids' => implode(',', $mediaIds) ?: null]
);
}
感谢您的任何想法。
mediaIds
array(1) {
[0]=>
string(19) "xxxxxxxx"
}
response from media post
object(stdClass)#1626 (5) {
["media_id"]=>
int(xxxx)
["media_id_string"]=>
string(19) "xxxxx"
["size"]=>
int(129032)
["expires_after_secs"]=>
int(86400)
["image"]=>
object(stdClass)#1623 (3) {
["image_type"]=>
string(9) "image/png"
["w"]=>
int(400)
["h"]=>
int(400)
}
}
Successfully posted item to twitter
object(stdClass)#1625 (23) {
["created_at"]=>
string(30) "Thu Dec 02 11:55:42 +0000 2021"
["id"]=>
int(1466375520866775045)
["id_str"]=>
string(19) "1466375520866775045"
["text"]=>
string(20) "New test message 401"
["truncated"]=>
bool(false)
["entities"]=>
object(stdClass)#1624 (4) {
["hashtags"]=>
array(0) {
}
["symbols"]=>
array(0) {
}
["user_mentions"]=>
array(0) {
}
["urls"]=>
array(0) {
}
}
["source"]=>
string(67) "<a href="https://www.co-kinetic.com" rel="nofollow">Co-Kinetic </a>"
["in_reply_to_status_id"]=>
NULL
["in_reply_to_status_id_str"]=>
NULL
["in_reply_to_user_id"]=>
NULL
["in_reply_to_user_id_str"]=>
NULL
["in_reply_to_screen_name"]=>
NULL
["user"]=>
object(stdClass)#1621 (43) {
["id"]=>
int(68679793)
["id_str"]=>
string(8) "68679793"
["name"]=>
string(13) "glen lockhart"
["screen_name"]=>
string(12) "glenlockhart"
["location"]=>
string(14) "Sheffield, UK."
["description"]=>
string(68) "I like tech and burritos and probably other things. Mostly burritos."
["url"]=>
NULL
["entities"]=>
object(stdClass)#1627 (1) {
["description"]=>
object(stdClass)#1628 (1) {
["urls"]=>
array(0) {
}
}
}
["protected"]=>
bool(false)
["followers_count"]=>
int(55)
["friends_count"]=>
int(163)
["listed_count"]=>
int(2)
["created_at"]=>
string(30) "Tue Aug 25 12:29:11 +0000 2009"
["favourites_count"]=>
int(109)
["utc_offset"]=>
NULL
["time_zone"]=>
NULL
["geo_enabled"]=>
bool(false)
["verified"]=>
bool(false)
["statuses_count"]=>
int(201)
["lang"]=>
NULL
["contributors_enabled"]=>
bool(false)
["is_translator"]=>
bool(false)
["is_translation_enabled"]=>
【问题讨论】:
-
从请求中得到什么
-
“这可能是由于新 v2 api 的变化造成的吗?此功能是否已被弃用?” - 您的通话仍针对 1.1 版本。即使有什么东西被弃用了,这通常只会影响新的 API 版本,在现有 API 版本中进行破坏更改是不应该发生的事情。
-
那么当你在 foreach 循环之后转储
$mediaIds的内容时,看起来应该是这样吗? -
感谢您的回复。媒体上传响应如下所示:``` object(stdClass)#1626 (5) { ["media_id"]=> int(1466371341519663105) ["media_id_string"]=> string(19) "1466371341519663105" ["size"] => int(129032) ["expires_after_secs"]=> int(86400) ["image"]=> object(stdClass)#1623 (3) { ["image_type"]=> string(9) "image/png" ["w"]=> int(400) ["h"]=> int(400) } } 所以,我们认为 Twitter 1.1 最近并没有改变 upload.twitter.com/1.1/media/upload.json 周围的任何东西?
-
我可以确认
/1.1/media/uploadAPI 端点最近没有变化。这应该仍然像过去一样工作。您正在返回media_id_string,这是应该发生的。
标签: php api twitter social-networking