[Telegram] Telegram(五) 取得 Chat ID

网站所有资源都有,可联系VX:bjlyxy1688

图片[1]-[Telegram] Telegram(五) 取得 Chat ID-天时网

  • 首先,在瀏覽器中輸入「https://api.telegram.org/botToken/getUpdates」,(紅色字體改為由 @BotFather 給予的 token ,取得 token 的方法請參考 [Telegram] Telegram(二) 建立 Bot 機器人 ),則會得到一串的 JSON ,如果得到的是如以下的 JSON ,表示頻道中沒有廣播訊息(好像會以天為單位,前一天就算有廣播訊息,也不會列出)。
{"ok":true,"result":[]}
  • 可先在頻道中輸入「Hello World」,然後再回到前一個步驟,將會得到以下的 JSON:
{"ok":true,"result":[{"update_id":720650387,
"channel_post":{"message_id":22,"chat":{"id":-123456789,"title":"頻道名稱","username":"機器人名稱","type":"channel"},"date":1582014900,"text":"Hello World"}}]}

排序後如下:

{
	"ok":true,
	"result":[
	{
		"update_id":720650387,
		"channel_post":
		{
			"message_id":22,
			"chat":
			{
				"id":-123456789,
				"title":"頻道名稱",
				"username":"機器人名稱",
				"type":"channel"
			},
			"date":1582014900,
			"text":"Hello World"
		}
	}]
}
  • 找到其中的 “chat:” id”:-123456789,就是我們需要的 Chat ID,接著就可以藉著這組 Chat ID ,使用程式來對頻道發送廣播訊息了。
  • 取得 Chat ID 之後,也可以試著在瀏覽器中輸入「https://api.telegram.org/botToken/sendMessage?chat_id=-123456789&text=Hello World」,紅色字體須改為自己的 token ,以及剛剛取得的 Chat ID ,應該就可以順利在頻道中廣播訊息了。
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
Worrying does not empty tomorrow of its troubles, it empties today of its strength.
担忧不会清空明日的烦恼,它只会丧失今日的勇气
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容