Telegram 使用 Bot API 获取频道个人资料照片
Telegram Get Channel Profile Photo using Bot API
我需要获取 Telegram 频道的头像。根据这个文档:
https://core.telegram.org/bots/api
我首先尝试使用 getChat 获取有关频道的基本信息。我成功了。它给了我这样的 json:
{"ok":true,"result":{"id":-1001003587533,"title":"\u06a9\u0627\u0641","username":"kafiha","type":"channel"}}
在此之后,我尝试使用 'getUserProfilePhotos' 来获取个人资料照片。但是我无法让它工作,因为当我传递从上次请求获得的 ID 或通道用户名 (@channelName) 时,它会以错误响应。
你知道我如何使用 Bot API for Telegram 来完成这个吗?
现在在 Bot API 中不可用。 getUserProfilePhotos 方法需要 user_id
参数,而不是您尝试的 chat_id
。
使用getChat(chat_id)
后,如果频道有照片,它returns一个包含照片对象的对象,那么你可以得到photo.big_file_id
并使用getFile(photo.big_file_id)
获取可下载频道照片的完整 link。如果 getChat(chat_id)
返回的对象不包含照片,则表示频道没有个人资料照片
这里是关于 Telegram 文档的更多信息。 https://core.telegram.org/bots/api#getfile
我需要获取 Telegram 频道的头像。根据这个文档: https://core.telegram.org/bots/api
我首先尝试使用 getChat 获取有关频道的基本信息。我成功了。它给了我这样的 json:
{"ok":true,"result":{"id":-1001003587533,"title":"\u06a9\u0627\u0641","username":"kafiha","type":"channel"}}
在此之后,我尝试使用 'getUserProfilePhotos' 来获取个人资料照片。但是我无法让它工作,因为当我传递从上次请求获得的 ID 或通道用户名 (@channelName) 时,它会以错误响应。
你知道我如何使用 Bot API for Telegram 来完成这个吗?
现在在 Bot API 中不可用。 getUserProfilePhotos 方法需要 user_id
参数,而不是您尝试的 chat_id
。
使用getChat(chat_id)
后,如果频道有照片,它returns一个包含照片对象的对象,那么你可以得到photo.big_file_id
并使用getFile(photo.big_file_id)
获取可下载频道照片的完整 link。如果 getChat(chat_id)
返回的对象不包含照片,则表示频道没有个人资料照片
这里是关于 Telegram 文档的更多信息。 https://core.telegram.org/bots/api#getfile