I'm trying to test a Google Cloud Function that sends messages to users. The relevant code is:
cred = credentials.ApplicationDefault()firebase_admin.initialize_app(cred, {"projectId": "redacted_project_id",})@functions_framework.httpdef send_messages(request): fcm_tokens = request_json.get('fcmTokens') message_text = request_json.get('message') message = messaging.MulticastMessage( data={'message': message_text}, tokens=fcm_tokens, ) response = messaging.send_multicast(message) if response.success_count > 0: logging.info("Message sent successfully") return jsonify({'success': True, 'message': 'Message sent successfully!'}), 200 else: logging.warning("Failed to send message. Responses: %s", len(response.responses)) for index, resp in enumerate(response.responses): if not resp.success: logging.error("Failed to send message to token %s: %s", fcm_tokens[index], resp.exception) return jsonify({'success': False, 'message': 'Failed to send message'}), 500I'm running this locally with functions-framework --target=send_messages. When calling the function, I see the output:
WARNING - Failed to send message. Responses: 2ERROR - Failed to send message to token e7...N6T2:APA...0bh: Your application is authenticating by using local Application Default Credentials. The fcm.googleapis.com API requires a quota project, which is not set by default. To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .ERROR - Failed to send message to token banana: Your application is authenticating by using local Application Default Credentials. The fcm.googleapis.com API requires a quota project, which is not set by default. To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .(Redacted part of the token)
I have no idea why this is happening-
- The page linked in the error says to run
gcloud auth application-default set-quota-project YOUR_PROJECT(which I did) echo $GOOGLE_CLOUD_PROJECTreturns the correct project idcat /home/$USER/.config/gcloud/application_default_credentials.jsonhas the correctquota_project_id(was set by runninggcloud auth application-default login)- My role in the Google Cloud Project is "Owner"