在App Engine标准Golang中初始化Firebase Admin

时间:2018-09-20 15:07:11

标签: firebase google-app-engine go firebase-authentication firebase-admin

我使用的是golang应用引擎标准。使用Firebase时,我始终收到403错误。这是我用于传递Firebase凭据的代码。这个api键是什么?我在做什么错了?

错误: googleapi:错误403:请求缺少有效的API密钥。禁止

credJSON := []byte("{...json from firebase console...}")
creds, err := google.CredentialsFromJSON(ctx, credJSON, "https://www.googleapis.com/auth/cloud-platform",
        "https://www.googleapis.com/auth/datastore",
        "https://www.googleapis.com/auth/devstorage.full_control",
        "https://www.googleapis.com/auth/firebase",
        "https://www.googleapis.com/auth/identitytoolkit",
        "https://www.googleapis.com/auth/userinfo.email")
if err != nil {
    return err
}
ops = append(ops, option.WithCredentials(creds))
fbApp, err := fb.NewApp(ctx, &fb.Config{ProjectID: projectID}, ops...)

1 个答案:

答案 0 :(得分:0)

如果通过nil进行配置,则结果为空。该库会找出Google Cloud上的凭据。因此,这是代码:

fbApp, err := fb.NewApp(ctx, nil, ops...)
if err != nil {
    return nil, err
}