A Alex_197 Well-Known Member Licensed User Longtime User Feb 12, 2024 #1 Hi all. I want to integrate the Firebase Push Notification with my asp,net website. But from what I read so far is that the token generated by B4J GetTokenValue is valid for 1 hour only. So if I start B4J sending tool and copy the token string from there and use it in my asp.net this token will expire in 1 hour. Is there any options to either convert GetTokenValue to vb.net /c# or to pass some parameters into B4J project?
Hi all. I want to integrate the Firebase Push Notification with my asp,net website. But from what I read so far is that the token generated by B4J GetTokenValue is valid for 1 hour only. So if I start B4J sending tool and copy the token string from there and use it in my asp.net this token will expire in 1 hour. Is there any options to either convert GetTokenValue to vb.net /c# or to pass some parameters into B4J project?
Erel B4X founder Staff member Licensed User Longtime User Feb 13, 2024 #2 Alex_197 said: or to pass some parameters into B4J project? Click to expand... What exactly do you mean? Upvote 0
Alex_197 said: or to pass some parameters into B4J project? Click to expand... What exactly do you mean?
DonManfred Expert Licensed User Longtime User Feb 13, 2024 #3 Alex_197 said: or to pass some parameters into B4J project? Click to expand... The given parameters are in Args. B4X: Sub AppStart (Form1 As Form, Args() As String) ... End sub I can´t help you with code in vb.net /c# to start an app and give parameters. In Delphi i use B4X: OpenProgram2('"C:\Java\jdk-11.0.1\bin\javaw.exe"',tempdir,'--module-path C:\Java\jdk-11.0.1\javafx\lib --add-modules ALL-MODULE-PATH -jar \\192.168.2.252\jars\UnternehmerErklaerung.jar '+IntToStr(abnr)+''); where IntToStr(abnr) is ust the string-interpretion of abnr (int). You can add more parameters. OpenProgram2 is just a helper-sub around ShellExecute B4X: procedure OpenProgram2(prog, path, params: string); var c, p, dir: array[0..800] of Char; begin StrPCopy(c, prog); StrPCopy(p, params); StrPCopy(dir, path); ShellExecute(0, 'open', c, p, dir, SW_NORMAL); end; Last edited: Feb 13, 2024 Upvote 0
Alex_197 said: or to pass some parameters into B4J project? Click to expand... The given parameters are in Args. B4X: Sub AppStart (Form1 As Form, Args() As String) ... End sub I can´t help you with code in vb.net /c# to start an app and give parameters. In Delphi i use B4X: OpenProgram2('"C:\Java\jdk-11.0.1\bin\javaw.exe"',tempdir,'--module-path C:\Java\jdk-11.0.1\javafx\lib --add-modules ALL-MODULE-PATH -jar \\192.168.2.252\jars\UnternehmerErklaerung.jar '+IntToStr(abnr)+''); where IntToStr(abnr) is ust the string-interpretion of abnr (int). You can add more parameters. OpenProgram2 is just a helper-sub around ShellExecute B4X: procedure OpenProgram2(prog, path, params: string); var c, p, dir: array[0..800] of Char; begin StrPCopy(c, prog); StrPCopy(p, params); StrPCopy(dir, path); ShellExecute(0, 'open', c, p, dir, SW_NORMAL); end;
A Alex_197 Well-Known Member Licensed User Longtime User Feb 13, 2024 #4 DonManfred said: The given parameters are in Args. B4X: Sub AppStart (Form1 As Form, Args() As String) ... End sub I can´t help you with code in vb.net /c# to start an app and give parameters. In Delphi i use B4X: OpenProgram2('"C:\Java\jdk-11.0.1\bin\javaw.exe"',tempdir,'--module-path C:\Java\jdk-11.0.1\javafx\lib --add-modules ALL-MODULE-PATH -jar \\192.168.2.252\jars\UnternehmerErklaerung.jar '+IntToStr(abnr)+''); where IntToStr(abnr) is ust the string-interpretion of abnr (int). You can add more parameters. OpenProgram2 is just a helper-sub around ShellExecute B4X: procedure OpenProgram2(prog, path, params: string); var c, p, dir: array[0..800] of Char; begin StrPCopy(c, prog); StrPCopy(p, params); StrPCopy(dir, path); ShellExecute(0, 'open', c, p, dir, SW_NORMAL); end; Click to expand... Thanks, That's what I need. Upvote 0
DonManfred said: The given parameters are in Args. B4X: Sub AppStart (Form1 As Form, Args() As String) ... End sub I can´t help you with code in vb.net /c# to start an app and give parameters. In Delphi i use B4X: OpenProgram2('"C:\Java\jdk-11.0.1\bin\javaw.exe"',tempdir,'--module-path C:\Java\jdk-11.0.1\javafx\lib --add-modules ALL-MODULE-PATH -jar \\192.168.2.252\jars\UnternehmerErklaerung.jar '+IntToStr(abnr)+''); where IntToStr(abnr) is ust the string-interpretion of abnr (int). You can add more parameters. OpenProgram2 is just a helper-sub around ShellExecute B4X: procedure OpenProgram2(prog, path, params: string); var c, p, dir: array[0..800] of Char; begin StrPCopy(c, prog); StrPCopy(p, params); StrPCopy(dir, path); ShellExecute(0, 'open', c, p, dir, SW_NORMAL); end; Click to expand... Thanks, That's what I need.
A Alex_197 Well-Known Member Licensed User Longtime User Feb 13, 2024 #5 Erel said: What exactly do you mean? Click to expand... I'm asking - is it possible to convert into C# or VB/NET this code B4X: Private Sub GetTokenValue (FilePath As String) As String Dim GoogleCredentials As JavaObject GoogleCredentials.InitializeStatic("com.google.auth.oauth2.GoogleCredentials") Dim Credentials As JavaObject = GoogleCredentials.RunMethodJO("fromStream", Array(File.OpenInput(FilePath, ""))) _ .RunMethod("createScoped", Array(Array As String("https://www.googleapis.com/auth/firebase.messaging"))) Credentials.RunMethod("refreshIfExpired", Null) Return Credentials.RunMethodJO("getAccessToken", Null).RunMethod("getTokenValue", Null) End Sub I need to send messages from my asp.net website. Upvote 0
Erel said: What exactly do you mean? Click to expand... I'm asking - is it possible to convert into C# or VB/NET this code B4X: Private Sub GetTokenValue (FilePath As String) As String Dim GoogleCredentials As JavaObject GoogleCredentials.InitializeStatic("com.google.auth.oauth2.GoogleCredentials") Dim Credentials As JavaObject = GoogleCredentials.RunMethodJO("fromStream", Array(File.OpenInput(FilePath, ""))) _ .RunMethod("createScoped", Array(Array As String("https://www.googleapis.com/auth/firebase.messaging"))) Credentials.RunMethod("refreshIfExpired", Null) Return Credentials.RunMethodJO("getAccessToken", Null).RunMethod("getTokenValue", Null) End Sub I need to send messages from my asp.net website.
Erel B4X founder Staff member Licensed User Longtime User Feb 14, 2024 #6 I guess that it is possible. You need to go over Google documentation and find whether they provide asp.net SDK and follow their instructions. Upvote 0
I guess that it is possible. You need to go over Google documentation and find whether they provide asp.net SDK and follow their instructions.
A Alex_197 Well-Known Member Licensed User Longtime User Feb 14, 2024 #7 Erel said: I guess that it is possible. You need to go over Google documentation and find whether they provide asp.net SDK and follow their instructions. Click to expand... Thank you. I will check it, But what if they don't have asp.net SDK? Upvote 0
Erel said: I guess that it is possible. You need to go over Google documentation and find whether they provide asp.net SDK and follow their instructions. Click to expand... Thank you. I will check it, But what if they don't have asp.net SDK?
Erel B4X founder Staff member Licensed User Longtime User Feb 14, 2024 #9 You can also create a B4J console app and run it from your server whenever you need to send a message. Upvote 0
You can also create a B4J console app and run it from your server whenever you need to send a message.
A Alex_197 Well-Known Member Licensed User Longtime User Feb 14, 2024 #10 Erel said: You can also create a B4J console app and run it from your server whenever you need to send a message. Click to expand... Thank you. Good idea. Upvote 0
Erel said: You can also create a B4J console app and run it from your server whenever you need to send a message. Click to expand... Thank you. Good idea.
LucaMs Expert Licensed User Longtime User Feb 14, 2024 #11 https://firebase.google.com/docs/reference/fcm/rest Upvote 0
tznikos Member Licensed User Longtime User Jun 6, 2024 #12 Hi, when run the code with the function GetTokenValue, getting the following error B4X: GoogleCredentials.InitializeStatic("com.google.auth.oauth2.GoogleCredentials") java.lang.ClassNotFoundException: com.google$auth$oauth2$GoogleCredentials Running from B4J Any idea why? Last edited: Jun 6, 2024 Upvote 0
Hi, when run the code with the function GetTokenValue, getting the following error B4X: GoogleCredentials.InitializeStatic("com.google.auth.oauth2.GoogleCredentials") java.lang.ClassNotFoundException: com.google$auth$oauth2$GoogleCredentials Running from B4J Any idea why?
DonManfred Expert Licensed User Longtime User Jun 6, 2024 #13 tznikos said: Hi, when run the code with the function GetTokenValue, getting the following error Click to expand... You are posting in the WRONG thread Posting to an existing thread is a mistake. Especially when the thema is a totally other one. You should ALWAYS create a new Thread for your Issue. PD: You probably forget to implement B4X: #AdditionalJar: google-auth-library-oauth2-http-1.18.0.jar #AdditionalJar: google-auth-library-credentials-1.18.0.jar #AdditionalJar: guava-23.0.jar #AdditionalJar: google-http-client-1.43.3.jar #AdditionalJar: google-http-client-gson-1.43.3.jar #AdditionalJar: gson-2.10.1.jar #AdditionalJar: opencensus-api-0.31.1.jar #AdditionalJar: opencensus-contrib-http-util-0.31.1.jar #AdditionalJar: grpc-context-1.27.2.jar #PackagerProperty: AdditionalModuleInfoString = uses com.google.auth.http.HttpTransportFactory; in your project. Last edited: Jun 6, 2024 Upvote 0
tznikos said: Hi, when run the code with the function GetTokenValue, getting the following error Click to expand... You are posting in the WRONG thread Posting to an existing thread is a mistake. Especially when the thema is a totally other one. You should ALWAYS create a new Thread for your Issue. PD: You probably forget to implement B4X: #AdditionalJar: google-auth-library-oauth2-http-1.18.0.jar #AdditionalJar: google-auth-library-credentials-1.18.0.jar #AdditionalJar: guava-23.0.jar #AdditionalJar: google-http-client-1.43.3.jar #AdditionalJar: google-http-client-gson-1.43.3.jar #AdditionalJar: gson-2.10.1.jar #AdditionalJar: opencensus-api-0.31.1.jar #AdditionalJar: opencensus-contrib-http-util-0.31.1.jar #AdditionalJar: grpc-context-1.27.2.jar #PackagerProperty: AdditionalModuleInfoString = uses com.google.auth.http.HttpTransportFactory; in your project.
tznikos Member Licensed User Longtime User Jun 7, 2024 #14 Alex here is your solution B4X: Imports System.IO Imports Google.Apis.Auth.OAuth2 Class Firebase Public Function GetToken() As String Dim fileName As String = "your file.json" Dim scopes As String = "https://www.googleapis.com/auth/firebase.messaging" Dim bearertoken As String Using stream As New FileStream(fileName, FileMode.Open, FileAccess.Read) Dim credential As GoogleCredential = GoogleCredential.FromStream(stream).CreateScoped(scopes) bearertoken = credential.UnderlyingCredential.GetAccessTokenForRequestAsync().Result End Using Return bearertoken End Function End Class Find from Nuget the library Google.Apis.Auth.OAuth2 Upvote 0
Alex here is your solution B4X: Imports System.IO Imports Google.Apis.Auth.OAuth2 Class Firebase Public Function GetToken() As String Dim fileName As String = "your file.json" Dim scopes As String = "https://www.googleapis.com/auth/firebase.messaging" Dim bearertoken As String Using stream As New FileStream(fileName, FileMode.Open, FileAccess.Read) Dim credential As GoogleCredential = GoogleCredential.FromStream(stream).CreateScoped(scopes) bearertoken = credential.UnderlyingCredential.GetAccessTokenForRequestAsync().Result End Using Return bearertoken End Function End Class Find from Nuget the library Google.Apis.Auth.OAuth2
hatzisn Expert Licensed User Longtime User Jun 7, 2024 #15 Alex_197 said: Thank you. Good idea. Click to expand... Alternatively you can create a B4J web app including the B4J sending tool and post a json to the web app in a handler. Upvote 0
Alex_197 said: Thank you. Good idea. Click to expand... Alternatively you can create a B4J web app including the B4J sending tool and post a json to the web app in a handler.
ddefrain Member Licensed User Longtime User Jun 17, 2024 #16 Alex_197 said: Hi all. I want to integrate the Firebase Push Notification with my asp,net website. But from what I read so far is that the token generated by B4J GetTokenValue is valid for 1 hour only. So if I start B4J sending tool and copy the token string from there and use it in my asp.net this token will expire in 1 hour. Is there any options to either convert GetTokenValue to vb.net /c# or to pass some parameters into B4J project? Click to expand... Firebase Notifications C# There you go @Alex_197 Note: If you handle a topic you don't need to use/send the FCM Token id; I mean send the topic instead of. And Yes Google Do that for security reasons the bearertoken lasts only one hour that's why you need to create a new one Extract of modified code B4X: public class Message { public string token { get; set; } public Data data { get; set; } public Notification notification { get; set; } public string topic { get; set; } } B4X: Root rootObj = new Root(); rootObj.message = new Message(); //rootObj.message.token = "cEM68BIdTomaE0R2dbaO:APA91bG8XfOjU_GSPNQYCrJ4wzE7VmMPEsyudwtE41VWKzJcoT2f3wbKsKCHwk5s078ZL31mM258-BzdZPRNXAlc_fyzCzj2txLQvQ3u7jggDPHjYIMlHRgspXT0CudfK"; //FCM Token id rootObj.message.data = new Data(); rootObj.message.data.title = "Data Title"; rootObj.message.data.body = "Data Body"; rootObj.message.data.key_1 = "Sample Key"; rootObj.message.data.key_2 = "Sample Key2"; rootObj.message.notification = new Notification(); rootObj.message.notification.title = "Notify Title"; rootObj.message.notification.body = "Notify Body"; rootObj.message.topic = "general"; Hope it helps! Upvote 0
Alex_197 said: Hi all. I want to integrate the Firebase Push Notification with my asp,net website. But from what I read so far is that the token generated by B4J GetTokenValue is valid for 1 hour only. So if I start B4J sending tool and copy the token string from there and use it in my asp.net this token will expire in 1 hour. Is there any options to either convert GetTokenValue to vb.net /c# or to pass some parameters into B4J project? Click to expand... Firebase Notifications C# There you go @Alex_197 Note: If you handle a topic you don't need to use/send the FCM Token id; I mean send the topic instead of. And Yes Google Do that for security reasons the bearertoken lasts only one hour that's why you need to create a new one Extract of modified code B4X: public class Message { public string token { get; set; } public Data data { get; set; } public Notification notification { get; set; } public string topic { get; set; } } B4X: Root rootObj = new Root(); rootObj.message = new Message(); //rootObj.message.token = "cEM68BIdTomaE0R2dbaO:APA91bG8XfOjU_GSPNQYCrJ4wzE7VmMPEsyudwtE41VWKzJcoT2f3wbKsKCHwk5s078ZL31mM258-BzdZPRNXAlc_fyzCzj2txLQvQ3u7jggDPHjYIMlHRgspXT0CudfK"; //FCM Token id rootObj.message.data = new Data(); rootObj.message.data.title = "Data Title"; rootObj.message.data.body = "Data Body"; rootObj.message.data.key_1 = "Sample Key"; rootObj.message.data.key_2 = "Sample Key2"; rootObj.message.notification = new Notification(); rootObj.message.notification.title = "Notify Title"; rootObj.message.notification.body = "Notify Body"; rootObj.message.topic = "general"; Hope it helps!
ddefrain Member Licensed User Longtime User Jun 19, 2024 #17 ddefrain said: Firebase Notifications C# There you go @Alex_197 Note: If you handle a topic you don't need to use/send the FCM Token id; I mean send the topic instead of. And Yes Google Do that for security reasons the bearertoken lasts only one hour that's why you need to create a new one Extract of modified code B4X: public class Message { public string token { get; set; } public Data data { get; set; } public Notification notification { get; set; } public string topic { get; set; } } B4X: Root rootObj = new Root(); rootObj.message = new Message(); //rootObj.message.token = "cEM68BIdTomaE0R2dbaO:APA91bG8XfOjU_GSPNQYCrJ4wzE7VmMPEsyudwtE41VWKzJcoT2f3wbKsKCHwk5s078ZL31mM258-BzdZPRNXAlc_fyzCzj2txLQvQ3u7jggDPHjYIMlHRgspXT0CudfK"; //FCM Token id rootObj.message.data = new Data(); rootObj.message.data.title = "Data Title"; rootObj.message.data.body = "Data Body"; rootObj.message.data.key_1 = "Sample Key"; rootObj.message.data.key_2 = "Sample Key2"; rootObj.message.notification = new Notification(); rootObj.message.notification.title = "Notify Title"; rootObj.message.notification.body = "Notify Body"; rootObj.message.topic = "general"; Hope it helps! Click to expand... it will return a response like this Last edited: Jun 19, 2024 Upvote 0
ddefrain said: Firebase Notifications C# There you go @Alex_197 Note: If you handle a topic you don't need to use/send the FCM Token id; I mean send the topic instead of. And Yes Google Do that for security reasons the bearertoken lasts only one hour that's why you need to create a new one Extract of modified code B4X: public class Message { public string token { get; set; } public Data data { get; set; } public Notification notification { get; set; } public string topic { get; set; } } B4X: Root rootObj = new Root(); rootObj.message = new Message(); //rootObj.message.token = "cEM68BIdTomaE0R2dbaO:APA91bG8XfOjU_GSPNQYCrJ4wzE7VmMPEsyudwtE41VWKzJcoT2f3wbKsKCHwk5s078ZL31mM258-BzdZPRNXAlc_fyzCzj2txLQvQ3u7jggDPHjYIMlHRgspXT0CudfK"; //FCM Token id rootObj.message.data = new Data(); rootObj.message.data.title = "Data Title"; rootObj.message.data.body = "Data Body"; rootObj.message.data.key_1 = "Sample Key"; rootObj.message.data.key_2 = "Sample Key2"; rootObj.message.notification = new Notification(); rootObj.message.notification.title = "Notify Title"; rootObj.message.notification.body = "Notify Body"; rootObj.message.topic = "general"; Hope it helps! Click to expand... it will return a response like this