'How to the manipulated data from google cloud function to the firebase remote config?

I have an android application and user data is stored on the firestore. I want to fetch that data and manipulate the results on Google Cloud Functions (for ranking system) with python and directly send those results to Firebase Remote Config, so that user can fetch the data from there.

In official document they have showed the same thing in pictureimgage.

But the description is totally different.Documentation.

So my question is: Can I send the Results which are calculated on the google cloud function directly to the firebase remote config?

Also we have a REST API to get and change Firebase Remote Config values. Is that possible that we can call this api at our Google Cloude Function?

. I am using this code which requires a token,however I am using this cloud function on the based on same account as Remore config

def _get():

Retrieve the current Firebase Remote Config template from server and store it locally.

headers = {
'Authorization': 'Bearer ' + _get_access_token()
 }
resp = requests.get(REMOTE_CONFIG_URL, headers=headers)

if resp.status_code == 200:
  with io.open('config.json', 'wb') as f:
    f.write(resp.text.encode('utf-8'))

 print('Retrieved template has been written to config.json')
 print('ETag from server: {}'.format(resp.headers['ETag']))
else:
 print('Unable to get template')
 print(resp.text)

Here is the code for Publish the data

`def _publish(etag):
 """Publish local template to Firebase server.
 Args:
  etag: ETag for safe (avoid race conditions)
 """
 with open('**config.json**', 'r', encoding='utf-8') as f:
 content = f.read()
 headers = {
  'Authorization': 'Bearer ' + _get_access_token(),
  'Content-Type': 'application/json; UTF-8',
  'If-Match': etag
}
 resp =  requests.
 put(REMOTE_CONFIG_URL,
 data=content.encode('utf-8'),headers=headers)
if resp.status_code == 200:
  print('Template has been published.')
  print('ETag from server: {}'.format(resp.headers['ETag']))
else:
  print('Unable to publish template.')
  print(resp.text)`

Just like I can access the firestore database without authentication in my cloud function why can't I update the Remote config without config.json? Function only have 2 files main.py and Requirements

If Authentication is necessary for google cloud function to update the Remote Config where can I store the config.json file?



Solution 1:[1]

It seems you'll be manually triggering the function whenever required. You can create an HTTP function and verify that it's you who has triggered it so no one else can.

from flask import escape
import functions_framework

def update_data_http(request):
    # 1. Verify the function is called by you
    # 2. Perform the calculations
    # 3. Update the result in Remote Config / Realtime Database
    return 'Data updated!!'

Firebase Admin SDK for Python doesn't include Remote Config so you would have to use Remote Config REST API to update the data. Using Realtime database for this might be a bit easier since you can update data directly using Admin SDK.

Can I send the Results which are calculated on the google cloud function directly to the firebase remote config?

Yes, using the REST API linked above.

Is that possible that we can call this api at our Google Cloude Function?

You can call any API from your Cloud function. Refer to this answer for calling APIs using Python: Making a request to a RESTful API using python

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Dharmaraj