如何运行firebase示例

joe*_*oel 2 github intellij-idea firebase firebase-realtime-database

我从这里克隆了一个firebase样本

https://github.com/firebase/quickstart-js

我想运行这个示例,我已经尝试过itellij和gitbash,但它没有运行

gio*_*r91 14

消息传递示例

  1. 安装Node.JS框架(此处为您的系统下载的链接).我将向您展示如何使用Linux,但程序应该是相同的.
  2. 使用命令行安装firebase CLI使用以下命令:( 如果失败则npm install -g firebase-tools可能需要sudo).
  3. 类型firebase login.这将打开您的浏览器并让您登录到您的Google帐户.
  4. 下载存储库 git clone https://github.com/firebase/quickstart-js.git
  5. 输入repo目录 cd quickstart-js
  6. 进入火力地堡控制台这里,然后Create new project
  7. 在项目的仪表板中,单击Add Firebase to your web application并复制提示给您的javascript代码.
  8. index.htmlmessaging文件夹中打开,在第83行打开从仪表板复制的代码.
  9. firebase initmessaging文件夹中键入命令,然后回答将要问您的问题:

    What Firebase CLI features do you want to setup for this folder?
    --> Hosting: Configure and deploy Firebase Hosting sites
    
    What file should be used for Database Rules?
    --> Blank, it is not relevant for this example.
    
    What do you want to use as your public directory? (public)
    --> .
    
    Configure as a single-page app (rewrite all urls to /index.html)?
    --> y
    
    File ./index.html already exists. Overwrite?
    --> N
    
    Run Code Online (Sandbox Code Playgroud)
  10. 键入命令firebase serve -p 8081(或您拥有的任何其他空闲端口)

  11. 转到http:// localhost:8081/index.html
  12. 单击Request permission(如果操作成功,将显示注册令牌)
  13. 在另一个标签页中,转到https://console.firebase.google.com/project/_/settings/cloudmessaging,选择您的项目并保存服务器密钥(长项)
  14. 类型

    curl -X POST -H "Authorization: key=YOUR-SERVER-KEY" -H "Content-Type:   
    application/json" -d '{
      "notification": {
         "title": "Portugal vs. Denmark",
         "body": "5 to 1",
         "icon": "firebase-icon.png",
         "click_action": "http://localhost:8081"
       },
       "to": "YOUR-IID-TOKEN"
    }' "https://fcm.googleapis.com/fcm/send"
    
    Run Code Online (Sandbox Code Playgroud)

    更换YOUR-SERVER-KEY用复制的服务器密钥,并YOUR-IID-TOKEN用字符串出现在这里点击后Request permission.如果一切正确完成,则会在此表单的本地页面中显示通知

    Received message:
    {
      "from": "xxxxxxxxxx",
      "collapse_key": "do_not_collapse",
      "notification": {
        "title": "Portugal vs. Denmark",
        "body": "5 to 1",
        "icon": "firebase-icon.png",
        "click_action": "http://localhost:8081"
      }
    }
    
    Run Code Online (Sandbox Code Playgroud)

数据库示例

您无需运行,firebase init因为该firebase.json文件已存在并已在存储库中配置.但如果你想使用它,你必须:

  1. 在页面head部分粘贴凭据(与上一步骤7相同)index.html.
  2. 转到firebase仪表板 - >您的项目 - >身份验证 - >身份验证方法,然后选择您想要的方法(电子邮件/密码,谷歌等)
  3. quickstart-js/database文件夹类型命令中firebase serve,应用程序将加载到此页面.
  4. 转到该页面并单击Sign in with Google,键入您的凭据,然后享受它!:-)

Auth示例

您无需运行,firebase init因为该firebase.json文件已存在并已在存储库中配置.要使用它(我没有尝试过),例如你应该:

  1. 将您的凭据粘贴facebook-credentials.htmlhead部分
  2. 在该script页面末尾的部分粘贴<YOUR_FACEBOOK_APP_ID>
  3. 在文件夹中键入quickstart-js/auth命令firebase serve,应用程序将加载到此页面.
  4. 转到localhost:5000并单击Facebook Login using OAuth Credentials (via Facebook Login Button)登录.

如果你想使用其他的方法,你就必须修改相应的文件,以同样的方式(facebook-popup.html,facebook-redirect,等)

随意询问是否不清楚.