Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase admin sdk build error #504

Open
hiteshkumar848 opened this issue Jul 28, 2022 · 1 comment
Open

firebase admin sdk build error #504

hiteshkumar848 opened this issue Jul 28, 2022 · 1 comment

Comments

@hiteshkumar848
Copy link

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)

}
@lahirumaramba
Copy link
Member

Hi @hiteshkumar848 Could you try changing your imports to the following instead:

	firebase "firebase.google.com/go/v4"
	"firebase.google.com/go/v4/messaging"

You can also refer to https://github.com/firebase/firebase-admin-go/blob/master/snippets/messaging.go for sample code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants