Skip to content

firebase admin sdk build error #504

Open
@hiteshkumar848

Description

@hiteshkumar848

Environment

  • Operating System version: macOS Monterey Version 12.4
  • Firebase SDK version: 4.8.0/ 3.13.0
  • Firebase Product: messaging

Problem

Getting the following on running go build main.go
vendor/github.com/firebase/firebase-admin-go/firebase.go:31:2: use of internal package firebase.google.com/go/internal not allowed

The error seems correct according to the document but then why is the internal package functions of firebase.google.com/go used in the admin sdk.

Steps to reproduce:

Failed to build and run the project for sending push notifications.

  1. Add the main.go file in the project.
  2. run the commands: go mod init, go mod tidy, go mod vendor

Relevant Code:

tried with go version: 1.14, 1.17

main.go

package main

import (
	"context"
	"firebase.google.com/go/messaging"
	"fmt"
	"github.com/firebase/firebase-admin-go"
	"log"
)

func main() {
	ctx := context.Background()
	app, err := firebase.NewApp(context.Background(), nil, nil)
	if err != nil {
		log.Fatalf("error initializing app: %v\n", err)
	}
	client, err := app.Messaging(ctx)
	if err != nil {
		log.Fatalf("error getting Messaging client: %v\n", err)
	}
        registrationTokens := []string{
	        "YOUR_REGISTRATION_TOKEN_1",
	        "YOUR_REGISTRATION_TOKEN_n",
        }
        message := &messaging.MulticastMessage{
	        Data: map[string]string{
		        "score": "850",
		        "time":  "2:45",
	        },
	        Tokens: registrationTokens,
        }
        br, err := client.SendMulticast(context.Background(), message)
        if err != nil {
	        log.Fatalln(err)
        }
        fmt.Printf("%d messages were sent successfully\n", br.SuccessCount)

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions