I have created Telegram bot from BotFather and it gave me an API key. Now when I am trying to open this URL
https://api.telegram.org/bot<MYAPIKEY>/sendMessage?chat_id=#<MYTELEGRAMUSERNAME>&text=Hello
it responds me
{
"ok": false,
"error_code": 400,
"description": "Bad Request: chat not found"
}
How to fix? What I forgot to do?
I was trying to open my bot's page in telegram and type there something (it didn't respond anything).
I want my computer to send Telegram notifications to me.
How can I receive messages from Telegram from URL ?
I can send message, if I make request on url:
https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s
I just need to enter "bot api token", "chat ID" and "text". I need something similar but I need to read messages in chat.
From the official documentation I understand that the way it works is something like this:
User installs app, FCM token is generated
Sending token to app server
Server uses token to send push-notifications to this device.
What if at the same time this user installs app on the other device - should I store multiple tokens per user on the app server? If yes - that means there should be something like checking for which ones are expired?
I also came across the exact challenge and had to resolve to a solution:
Storing each token for the user against the device id.
It's interesting enough to know that this function in fact exists in the firebase messaging method. But more surprising is the fact that there's no documentation to handle such scenario.
https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId.html#getId()
Summarily, while sending the new token to the server, also send along the device id returned by the getId() method and use it to enforce uniqueness of token per device.
And to also apply this solution while taking advantage of device grouping feature of FCM, you can make a server request on the FCM group, in order to delete the old token on that device-id before replacing it with the new.
What if at the same time this user installs app on the other device - should I store multiple tokens per user on the app server?
Yes. A user could have multiple devices, a case where Device Groups are commonly used.
If yes - that means there should be something like checking for which ones are expired?
If a token expires, a callback is triggered (onTokenRefresh() for Android), from where you'll have to send the new token to your App Server and delete the old one corresponding to the user/device.
Graykos, You can do sth like this:
Each time a user have a new login, get a new token from google, and when logout delete that token (Edit note: Close app & run it again, not called a new login and it's not create a new token).
So if user login from multiple device/browser OR multiple user login from one device/browser one after the other, you can nicely handle all of that.
in this way "multiple user login from one device/browser one after the other", all of them have the same token (so delete and renew for each login)
As Andres SK mentioned in the first comment of your question, you can delete the token when failure happen (maybe the lost device that user cannot logout from).
I came across the same problem, How I tried to solve this is to maintain a data structure like this. And save this data to my notifier server's database.
type UserToken struct {
UserId string
Tokens []DeviceToken
}
type DeviceToken struct {
DeviceName string
Token string
}
Whenever you get a new device token from firebase just replace the existing one with new one for that device.
And for the web part I think storing the last one is enough.
I have a similar situation and found out the following error response code when trying to send to an expired token:
{
"error": {
"code": 404,
"message": "Requested entity was not found.",
"status": "NOT_FOUND",
"details": [
{
"#type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "UNREGISTERED"
}
]
}}
My app server accepts multiple tokens per user assuming they use multiple devices. When sending a new message, I will try to send it to all tokens related to the user. Those that return this error will be deleted so future message will only be sent to active tokens.
I'm trying to get Google Calendar Push Notifications working for Resources (aka Rooms). They work perfectly for user calendars, but when I call/watch on a Resource, it successfully creates. I get the initial "Sync" call on the server, but then I never hear back from Google again.
My approach to creating the watch is to authenticate an administrator, and use that Token to add the watch on the resource that the administrator had added as a calendar to his list, so it's showing up in the calendarList/list call. I've also turned on all notifications on the admin's account for that calendar.
Any idea on what I might be doing wrong?
Make sure that you register the domain of your receiving URL. If you plan to use https://domain.com/notifications as your receiving URL, you need to register https://domain.com. Each watchable Google Calendar API resource has an associated watch method at a URI of the following form:
https://www.googleapis.com/apiName/apiVersion/resourcePath/watch
You need to send a POST request to the watch method for the resource to set up a notification channel for messages about changes to a particular resource.
POST https://www.googleapis.com/calendar/v3/calendars/my_calendar#gmail.com/events/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
{
"id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://domain.com/notifications", // Your receiving URL.
...
"token": "target=myApp-myCalendarChannelDest", // (Optional) Your channel token.
"expiration": 1426325213000 // (Optional) Your requested channel expiration time.
}
}
Each notification channel is associated both with a particular user and a particular resource (or set of resources). A watch request will not be successful unless the current user owns or has permission to access this resource.
Check this documentation.
I want to Search the person basic information like email,name,address etc by passing there email id on graph API of facebook. But its not working and its returning me the message
"error": {
"message": "(#200) Must have a valid access_token to access this endpoint",
"type": "OAuthException",
"code": 200
}
I am passing url like below-
https://graph.facebook.com/search?q=EMAIL_ID&type=user&access_token=ACCESS_TOKEN
Please suggest me how can I able to search information by passing email id in graph api. and also if I logged out and then logged in back then my this access_token is not working. Do I need to get different access token each time? Please suggest.
Thanks