Firebaseの使い方
Firebase consoleから行うこと
create new project
analyticsなし
左のカラムの下のUpgradeから料金プランを変更→Planを従量のBlazeにする(無料のSparkだと外部APIアクセスができません)
GitPodから行うこと
下記のコマンドをターミナルに入れて実行していってください
npm install -g firebase-tools
firebase login --no-localhost
firebase init functions
Use an existing project(選択肢の中から方向キーで選ぶ)
What language would you like to use to write Cloud Functions?
JavaScript
Do you want to use ESLint to catch probable bugs and enforce style?
No
File functions/package.json already exists. Overwrite?
No
File functions/index.js already exists. Overwrite?
No
File functions/.gitignore already exists. Overwrite?
No
Do you want to install dependencies with npm now?
Yes
環境変数の設定
firebase functions:config:set --project YOUR_FIREBASE_PROJECT_ID line.channel_secret=YOUR_LINE_CHANNEL_SECRET line.access_token=YOUR_LINE_ACCESS_TOKEN
firebase project IDの確認の仕方:firebase consoleで歯車クリック→プロジェクトの設定→project ID
firebase --project YOUR_FIREBASE_PROJECT_ID functions:config:get で設定されているか確認
参考: camelCaseを使うとこういうエラーが出る Error: Invalid config name azure.computerVisionKey, cannot use upper case.
参考: ドットなしだとこういうエラー Error: Invalid argument, each config value must have a 2-part key (e.g. foo.bar).
cd functions
npm install
firebase deploy --project YOUR_FIREBASE_PROJECT_ID --only functions,hosting
Hosting URLをコピー or firebase consoleの開発→HostingからURLを入手
LINEのwebhook URLの所に後ろに /webhookとつけて設定
接続確認では失敗しますが、テキストをLINEアプリから送っておうむ返しで同じものが帰ってくれば大丈夫です
firebaseのプラン変更
右下のアップグレードからBlazeに変更する(無料のSparkだと外部APIが使用できないため)
その他
Developt -> Funcitons -> Logs
Microsoft Azure Computer Visionを使う場合
cd functions
npm install microsoft-computer-vision --save
firebase functions:config:set --project YOUR_FIREBASE_PROJECT_ID azure.computer_vision_key=YOUR_AZURE_COMPUTER_VISION_SUBSCRIPTION_KEY
再度デプロイ
firebase deploy --project YOUR_FIREBASE_PROJECT_ID --only functions,hosting
参考