'Firebase functions using backend as a service, when migrating to Http v1 how to Send to topic and Get user subscribed topics

Firebase allows us to send notification messages via our own application by making POST request. we were using this legacy way to get topics subscribed by the user via GET request .

var url = $"https://iid.googleapis.com/iid/info/{firebaseToken}?details=true";
  var serverKey ="key=myKey";

  using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
  {
    webRequest.SetRequestHeader("Content-Type", "application/json");
    webRequest.SetRequestHeader("Authorization", serverKey);
    // Request and wait for the desired page.
    yield return webRequest.SendWebRequest();

  }

and this code for Sending to topic via POST request

var url = "https://fcm.googleapis.com/fcm/send";
var serverKey = "key=my_key";
// the message to send
data.message.topic = "mobile";
data.message.notification.title = "Breaking news";
data.message.notification.body = "News Available";
data.message.data.story_id = "story_1234";
var jsonString = JsonUtility.ToJson(data);
  
  var webRequest = UnityWebRequest.Post(url, "POST");
  
  var bodyRaw = Encoding.UTF8.GetBytes(jsonString);
  
  webRequest.SetRequestHeader("Content-Type", "application/json");
  webRequest.SetRequestHeader("Authorization", serverKey);
  
  webRequest.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
  webRequest.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
  
  // Request and wait for the desired page.
  yield return webRequest.SendWebRequest();

Reference link

now according to the Firebase documentation, if we migrate to the new Http v1 API, we have start using a valid Oauth 2.0 token to make the POST request using this new URL

POST https://fcm.googleapis.com/v1/projects/Myproject-ID/messages:send

now trying to POST using the new url but older server key we are getting an Http 404 error, so how would we get a valid Oauth 2.0 token within unity or a BaaS to test this.

My concerns being

  1. Can I keep using legacy way if it is not being deprecated, as I cant find any information regarding it being deprecated
  2. Is it possible to use the OAuth 2 Client ID provided by a service account in google cloud platform to authorize sending to topics.

Edit: If anyone can provide a curl example which uses server key or a server level oauth code (and from where to find one) that would also be helpful



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source