How to create a push id for firebase using golang? - firebase

i want to push a map to firebase with an id (eg:-KfKoScgRhylaLjQlK-y)
fitToWorkMap := make(map[string]models.TaskFitToWork)
fitToWorkForTask :=models.TaskFitToWork{}
for i := 0; i < len(FitToWorkSlice); i++ {
fitToWorkForTask.Info =FitToWorkSlice[i]
fitToWorkForTask.DateOfCreation =time.Now().Unix()
fitToWorkForTask.Status = helpers.StatusPending
fitToWorkMap["fgsgdsfn+'i'"] = fitToWorkForTask
}
task.FitToWork = fitToWorkMap
here fitToWorkMap is a map .i want to generate a key for this map

Those keys starting with -K are called push IDs and they are automatically generated by Firebase:
When you call push() or childByAutoId in one of the supported SDKs
When you perform a POST request to the REST API
There is no Firebase SDK for Go and uses the REST API to interact with the Firebase Database. That means that it only generates a push ID when it POSTs a new node to the database. I don't know of any library for Go to generate Firebase push IDs client-side.
But luckily the keys are quite well documented in a blog post. The code for a JavaScript implementation of generatePushID() is also available, so you could port that over to Go.

Related

Find Updated events from Google Watch Push Notification Response

I have created a watch Channel on my calender and I am successfully receiving all updates from Google PUSH Notifcation.
But I am not able to use that response to get craeted/updated events.
I read few docs and SO questions that I need to use X-Goog-Resource-ID from the response and hit events list API.
But value of this X-Goog-Resource-ID is neither a calender id and neither it is a event id so how can I use this in events list API ?
I am using Python and Service Account for the integration.
Documentaion :
https://googleapis.github.io/google-api-python-client/docs/dyn/calendar_v3.events.html#list
https://developers.google.com/calendar/api/guides/push#making-watch-requests
Response from PUSH :
"X-Goog-Channel-Expiration": "",
"X-Goog-Channel-ID": "",
"X-Goog-Channel-Token": "",
"X-Goog-Message-Number": "",
"X-Goog-Resource-ID": <resource id>,
"X-Goog-Resource-State": "exists",
"X-Goog-Resource-URI": <calender UI>
Google Functions I tried using :
service = build('calendar', 'v3', credentials=credentials)
service.calendars().get(calendarId=X-Goog-Resource-ID).execute()
service.events().list(calendarId=calenderId', eventId=X-Goog-Resource-ID).execute()
Is their any ref Python Example of using digesting Calender PUSH Notification or which API/Function I need to call with what oaarms to get the created/updated events ?
The X-Goog-Resource-ID header holds a value that identifies that particular resource across the APIs. The whole push notifications basically informs you that something has changed on that calendar.
Now if you want to know exactly what changed, I strongly advise you to perform a synchronisation. One way to do this is to perform a full synchronisation and store the nextSyncToken. Then, when you receive a push notification telling you about a change in the calendar, you only have to use the syncToken to know what has changed since your last synchronisation. You can see a working full example on the linked docs.
UPDATE
If you are watching multiple calendars through push notifications, you will need a system in place to track which calendar is being modified at a time. The X-Goog-Resource-ID header maps with the Calendar ID, and it can be used along syncToken to run a events.list() request to receive the updated events.

How to get query parameters value from deep link while dynamic link created using AppInvitation class using Firebase?

In my app, I am sending invitation to people to join my app. I am using AppInvitation IntentBuilder Class to create Intent. After these steps, one URL-link gets generated that we can send to invitees.
I have written below code to generated that link and start the activity to send the link. I am able to send invites and able to successfully launch the app by clicking the dynamiclinks. Both the dynamically and manually created ones.
IDictionary<string, string> values = new Dictionary<string, string>();
values.Add("utm_campaign", "Health");
values.Add("utm_medium", "GoIbibo");
values.Add("ad", "1");
values.Add("credit", "50");
values.Add("utm_source", "Yahoo");
values.Add("afl", "https://www.facebook.com");
var intentbuidl = new AppInviteInvitation.IntentBuilder(MainActivity.mainActivity.GetString(Resource.String.invitation_title))
.SetMessage(MainActivity.mainActivity.GetString(Resource.String.invitation_message))
.SetDeepLink(Android.Net.Uri.Parse(MainActivity.mainActivity.GetString(Resource.String.invitation_deep_link)))
.SetAdditionalReferralParameters(values)
.Build();
MainActivity.mainActivity.StartActivityForResult(Intent.CreateChooser(intentbuidl, "Install"),0);
Generated link: https://aku4q.app.goo.gl/i/619426442529-4a4105fd-33ea-4b0f-bf07-6f4063eef8f8
So my question is, when do invitees open the app using this link? Can we be able to get these additional parameters which I have set using IDictionary from the above generated link?
To my knowledge, no. This is one of the limitations of Firebase deep linking — you can't pass custom parameters and need to use the URL string for everything.
You could check out Branch.io (full disclosure: I'm on the Branch team) for an alternative approach that does allow custom parameters.

Firebase database change automatically [duplicate]

Given the starting time/date and duration, how can I make a server side calculation that determines if an object is "finished", "in progress", or "upcoming"
--Show
--duration: "144"
--startDate: "2015-11-10"
--startTime: "14:00"
--status: "?"
Client-side javascript to determine if the show has started yet:
// if negative, then show hasn't started yet
var time = (-(startdate.getTime() - currentdate.getTime()) / 1000 / 60);
Client-side javascript to determine if the show has finished running yet:
// if negative, then show has finished
var timeLeft = channelDuration - timerStartTime;
There is no way to run your own server-side code on Firebase. See:
Common Firebase application architectures
Firebase Hosting with own server node.js
How would I run server-side code in Firebase?
How to write custom code (logic) when using firebase
But you can store a server-side timestamp, which seems what you're trying to do:
ref.child('Show/startTimestamp').set(Firebase.ServerValue.TIMESTAMP);
You can then get the shows that haven't started yet with:
var shows = ref.child('Shows');
ref.orderByChild('startTimeStamp').startAt(Date.now()).on(...
For someone passing by, I think now Firebase allow you to do this by Cloud Function. For this case, you can create the function that determine the status of the status by other parameter when the data is added to you database.
Please checkout
https://firebase.google.com/docs/functions/

Is there a way to generate a push ID from the Console in the new Realtime Database?

I have a listing node in my Database and wanted to add data into it from the web console. I want to have a push ID as the key of the object. Something like this :
{
"listing": {
"4acd4g1OreMyo2FkW6DlQH7ZhvY2": {
"name": "abc",
"location": "xyz"
}
}
}
where '4acd4g1OreMyo2FkW6DlQH7ZhvY2' would be the auto generated push ID.
I know it can be done using the Android/iOS/JS SDKs (using the push method). But is this possible from the console?
No, the console doesn't support it currently. I've been using firebase for a while and I've never needed it :)
while firebase console doesn't support it officially, there is a service called mockaroo that can generate firebase random id. Make sure to pick firebase option in the format dropdown

Parse, how to send push notification to targeted users

I have successfully setup parse push notifications and in my installation table I have both an installation, and device token. What I'm really trying to do is send a push notification to certain users, rather than certain devices. How do I bing the installations table to the uses table, so that I can make a query by users and get back a deviceid to push to
From https://parse.com/docs/push_guide#top/iOS, section "Using Advanced Targeting".
You can even create relationships between your Installation objects
and other classes saved on Parse. To associate a PFInstallation with a
particular user, for example, you can simply store the current user on
the PFInstallation.
// Associate the device with a user
PFInstallation *installation = [PFInstallation currentInstallation];
installation[#"user"] = [PFUser currentUser];
[installation saveInBackground];
Now you can create a query on the installation table, where "user" is the user you want to send a push notification to.
Finally, use that query when constructing the push object.
Example in Objective-C (adjust accordingly, if you're sending the push in some other language):
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:#"user" equalTo:someUser]; // where some user is the user object that is to receive a push notification
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
[push setMessage:#"Hi there!"];
[push sendPushInBackground];

Resources