Get activate notification in flutter with FCM - flutter

I have a flutter social network app with firebase
I want to send notification to user when they get follow,like,comment or any activity
I know firebase cloud massaging do this but how
I want the exact code for this or some thing near with it

You can archive in 2 ways but in both ways you required user's fcm_token or device_token and firebase Server key.
Use this API - https://fcm.googleapis.com/fcm/send to send push notifications to specific users.
If you have own server
Manage via own server (secure & most preferred)
Crate your own API for send notifications to specific user. From your backend get that user's fcm-token & fire actual push API from your server.(firebase server key not save on mobile platform)
Do not include the server key anywhere in your client code. Also, make sure to use only server keys to authorize your app server.
If you don't have own server.
You need to add firebase sever_key in front-end means app code. (Less preferable)
Just call actual firebase push API from your app code.
Note: in both ways you required receiver fcm_token or device_token. Because you need to pass firebase server_key & this token in that API.
Reference links
1.official latest documentation for API link1
Another reference link2
API official doc - link3

Related

Looking for a secure way to store and read json file in serverless flutter using firebase

I'm making a mobile app using flutter and firebase.
To use Cloud Messaging of firebase, I need to send server key of firebase by putting in headers and sending with http post method.
headers: {
'Authorization': server key
}
However, it is not a recommended way to use server key. Firebase recommends to download json file of service account and use that file to get JWT token from firebase. Otherwise, I have to use Admin SDK and it's difficult for us because we don't have a backend server.
Therefore, my question is that are there any good ways to store json files in client side or local environment or firebase or Azure and can read the file only when we need it.
Plus, if you know the better way to send FCM from client side, please let me know. Thank you so much for reading it.
I have to use Admin SDK and it's difficult for us because we don't
have a backend server.
You can very well use the Admin SDK with Cloud Functions for Firebase, the "serverless framework that lets you run backend code". It is very common to use Cloud Functions to send message requests to the FCM backend, which then routes messages to client apps running on users' devices.
There is actually an official example that demonstrates how to send an FCM notification from a Realtime Database triggered Function. You can adapt it to be triggered by any other available trigger mechanism.

Why do I need to use admin SDK with Cloud Functions to send notifications to other device using FCM in Flutter?

Im new to Flutter.
I wondered why I need to use Cloud Functions to send notifications to the other device in Flutter.
If one device simply know the token of the partner device, I think that it can specify the token and send a notification directly from the client side.
Does this question relate to this answer?
How to send push Notification using FCM and Flutter(One to Another Device)?
Thank you.
You certainly could send the message directly from your client app, but you would then have a huge security problem. The Admin SDK requires a service account to initialize, and you would have to package that service account in your app so it could call the FCM API.
Distributing your service account is strongly discouraged, as it now allows everyone to do everything to your project that the service account is allowed to do. This could be anything and everything.
Instead, people put messaging code on secure backends where the service account can't be seen by others. Cloud Functions is a popular option for this, but you can use whatever backend you want.

Google Assistant actions on google

All my hardware is already developed. I use MQTT for communication between my devices, I have lights, fans, heaters and many more ioT appliances. I can controll all of these from my Android application which i have built. I would like to use Google Assistant to control my devices as well. The status of my lights (on/off) are stored in a sql database and when ever a change occurs to the database(detected by the hardware) my hardware can control that specific light. In My Android app i do the same thing which is updating the databases value(on/off) of the light and the change is detected by my hardware platform. Can i use Google Assistant to update a sql database value?
I can create a webserver( ASP.NET C#) and pass the command to the sql database of my relevant customer if google assistant can invoke the username or email, lightID, command to my webserver. Can google assistant do this? If not how would achieve this.
It sounds like you want to take a look at the Actions on Google Smart Home API which will let the Assistants Smart Home controls work with your control server directly.
Without knowing exactly how your database or existing web server are configured or hosted, I can speak only broadly at best. Your web server will need to implement two primary things:
You'll need an OAuth2 server that can issue tokens that represent your users. This is how Google will associate the user's account on the Assistant with your account, and how Google will identify (to you) which user is issuing the command.
You will need to implement a webhook at a URL on your web server. This webhook will be sent a POST message containing a header with a valid auth token (that you issued) and a JSON body. The JSON will contain information about the command that has been issued by the user. Your HTTP reply body will also be JSON. For details of the JSON formats and all the fields that it can send and that you must reply with, consult Google's documentation.
There are a number of different commands (which Google calls "intents") that Google can send you on behalf of the user. You should be able to handle all of them by either querying or modifying your database:
SYNC - A request for what devices this user has, some of their configuration information, and what commands they respect.
QUERY - What is the current state of the devices for this user.
EXECUTE - Change the state on some of the user's devices.
RESYNC - (Future update) A re-request of the user's device info.

how to import JSON data from rest API to google firebase?

I am planning to use Firebase as my backend service for the mobile application. As part of the functionality, I need to get the data from external rest API which returns JSON data. I need to update the data periodically so that I can have updated information.
I have an option to call the rest API and update firebase on the mobile application however it is not the right approach. I prefer to keep this logic on the backend service.
Is there a way to use Firebase cloud function to periodically update firebase database from external Rest API?
#Ioki, I assume what you are trying to do is make a mobile app which gets updated data every time a user goes to the app but you want this to be on the backend. I haven't tried it but you might want to use Node js with their Firebase Admin SDK.
See the link: https://firebase.google.com/docs/admin/setup
Although I think it might make more sense to use the real-time database via the iOS/ Android SDK because automatic/ value event updates are basically the purpose of the real- time database. Good luck! :)

Subscribing to realtime updates for an app that is marked as "native'

When I follow the instructions on:
http://developers.facebook.com/docs/reference/api/realtime/
Namely:
1) Retrive an access_token with:
https://graph.facebook.com/oauth/access_token?client_id=<APP_ID>&client_secret=<APP_SECRET>&grant_type=client_credentials
2) Issue a subscription request to https://graph.facebook.com/<app-id>/subscriptions?access_token=...
I receive the error:
{"error":{"message":"(#15) This method is not supported for native apps","type":"OAuthException","code":15}}
My app is marked as a native app under "App Type" on https://developers.facebook.com/apps/<app id>/advanced.
But, to be clear, I am making the subscription request from a server (the same server that I intend to use as my callback server).
So, questions:
Should I be getting an access_token via some other means? Does
the way I'm getting the access token
("grant_type=client_credentials") mean that I'm getting an access token that is supposed to be for a client, rather than a server?
Am I doing something else wrong? Or,
is this just a bug / documentation bug? Nowhere in the realtime API
docs does it say that Native apps are not alllowed to use the realtime API.
Related questions:
How do I subscribe to Facebook Realtime API? is basically my same question, but it's not on facebook.stackoverflow.com and it was answered with a non-answer, so I saw fit to repost.
http://facebook.stackoverflow.com/questions/11141333/using-real-time-updates-from-facebook-graph-api-with-a-client-application is a related question, but again, I am making a subscription request from a SERVER, not a client.
If you setup a canvas_url, you can do client_credentials. So setup native AND canvas (server). It will host a web site version of your app, which is what FB needs to grant that kind of access_token.