如何运行firebase示例

时间:2016-12-22 11:24:46

标签: github intellij-idea firebase firebase-realtime-database

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

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

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

1 个答案:

答案 0 :(得分:13)

消息传递示例

  1. 安装Node.JS框架(here为您的系统下载的链接)。我将向您展示如何使用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. 下载存储库
  6. 输入repo目录cd quickstart-js
  7. 转到Firebase控制台here,然后转到Create new project
  8. 在项目的信息中心中,点击Add Firebase to your web application并复制提示给您的javascript代码。
  9. index.html文件夹中打开messaging,在第83行打开从信息中心复制的代码。
  10. firebase init文件夹中输入命令messaging,然后回答将要问你的问题:

    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
    
  11. 输入命令firebase serve -p 8081(或您拥有的任何其他空闲端口)

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

    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"
    

    使用复制的服务器密钥替换YOUR-SERVER-KEY,并在点击YOUR-IID-TOKEN后使用here字符串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" } } 。如果一切都正确完成,则会以local page的形式显示通知

    firebase init
  16. 数据库示例

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

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

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

      1. 将您的凭据粘贴到head部分的script
      2. 在该页面末尾的<YOUR_FACEBOOK_APP_ID>部分粘贴quickstart-js/auth
      3. 键入文件夹firebase serve命令Facebook Login using OAuth Credentials (via Facebook Login Button),应用程序将加载到this page
      4. 转到localhost:5000并点击facebook-popup.html登录。
      5. 如果您想使用其他方法,则必须以相同的方式修改相应的文件(facebook-redirect#include "stdafx.h" #include <iostream> using namespace std; class Ec { public: float a, b; //equation's parameters public: Ec() {float x, y; cout <<"a= "; cin >> x; cout << "b= "; cin >> y; a = x; b = y; cout << "void constr\n";}; Ec(float x, float y) { a = x; b = y; cout << "param constr\n"; } ~Ec() { cout << "destr\n"; } Ec(Ec &z) { a = z.a; b = z.b; cout << "cpy constr\n"; } friend float half1(Ec); //function to return a/2 friend float half2(Ec); //function to return b/2 friend float sol1(Ec); //function to return the solution for the standard eq friend float sol2(Ec); //function to return the sol for the /2 param eq }; float half1(Ec ec1) { return (ec1.a / 2);} float half2(Ec ec1) { return (ec1.b / 2); } float sol1(Ec ec1) { float x; return x = -ec1.b / ec1.a; } float sol2(Ec ec1) { float x2; return x2 = -half2(ec1) / half1(ec1); } int main() { int x, y; cout << "a= "; cin >> x; cout << "b= "; cin >> y; Ec ec1; Ec ec2(x, y); Ec ec3 = ec1; //the couts display for ex:" ec 2x+1=0 has sol -0.5" cout << "ec " << ec1.a << "x+ " << ec1.b << "=0 has sol " << sol1(ec1) << endl; cout << "ec " << ec2.a << "x+ " << ec2.b << "=0 has sol " << sol1(ec2) << endl; cout << "ec " << ec3.a << "x+ " << ec3.b << "=0 has sol " << sol1(ec3) << endl; cout << "ec halved " << half1(ec1) << "x+ " << half2(ec1) << "=0 has sol " << sol2(ec1) << endl; cout << "ec halved " << half1(ec2) << "x+ " << half2(ec2) << "=0 has sol " << sol2(ec2) << endl; cout << "ec halved " << half1(ec3) << "x+ " << half2(ec3) << "=0 has sol " << sol2(ec3) << endl; } return 0; } 等。)

        随意询问是否不清楚。