Reputation: 145
I am trying to get my chat_id for my telegram channel. Bot I get this line error:
{"ok":false,"error_code":401,"description":"[Error]: Unauthorized"}
My Channel Name is: MyName
My link is: https://telegram.me/MyNameIsChannel.
Upvotes: 4
Views: 20613
Reputation: 485
The first and the main reason of the problem is that I'm using my telegram on a phone only and have to type the token manually on a Laptop keyboard. That was the case. No firewalls, no extra installation (of some software) was a reason but a SIMPLE TYPO. Better just COPY&PASTE the token whatever way you can.
Don't forget about the "bot" suffix and upper/lowercase letters also matters.
I've spent so many time for googling/troubleshooting and in fact it was a simple typo.
Upvotes: 6
Reputation: 3067
Looks like you aren't passing your bot's token to the query.
If your channel is public with username @MyNameIsChannel and your bot's token is AAAAA, then you should make this request to find out channel's id (just send any message and watch chat_id
in reply JSON):
https://api.telegram.org/bot147772105:AAEGOblbPGiU9Hfoy7wVFt0bVfJsdO3iis4/sendMessage?text=Hello&chat_id=@MyNameIsChannel
Please check beforehand that your bot is admin of that channel.
Upvotes: 4
Reputation: 21
Try obtaining the ID of this channel. Usually, the API requires the ID of the channel as string.
Would become
(Most channels and groups have a - sign at the beginning. Make sure you'll copy it to make it work nicely.)
Upvotes: 2