0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

firebase web codelab 11. show notifications をWindowsで突破する

Last updated at Posted at 2020-05-30

はじめに

firebaseのweb codelabをWindowsで試していたら、「11. show notifications」でハマりました。
Windows 10で試しています。
curlはいつの間にかインストールされていましたが、node.jsとセットで入るのかな?

事象

こちらを参照。
https://codelabs.developers.google.com/codelabs/firebase-web/index.html#10

Google様の通知用プラットフォームを介して、WebAPI経由でDeviceにNotificationするっていう内容だと思います。

curlでこのコマンド投げろ^^って言われます。
けど、投げたらJSON_PARSING_ERROR: Unexpected character (') at position 0.でエラーになってしまいます。

curl_template_by_google
curl -H "Content-Type: application/json" \
     -H "Authorization: key=YOUR_SERVER_KEY" \
     -d '{
           "notification": {
             "title": "New chat message!",
             "body": "There is a new message in FriendlyChat",
             "icon": "/images/profile_placeholder.png",
             "click_action": "http://localhost:5000"
           },
           "to": "YOUR_DEVICE_TOKEN"
         }' \
     https://fcm.googleapis.com/fcm/send

解決法

エラー内容の通り、jsonのparseに失敗しています。
以下で解決。

  • json中の"""にエスケープ
  • 文字列を括る記号を'"に変更
  • コマンドの途中改行をやめて1行に
curl_template_by_me
curl -H "Content-Type: application/json"      -H "Authorization: key=YOUR_SERVER_KEY"      -d "{""notification"": { ""title"": ""New chat message!"", ""body"": ""There is a new message in FriendlyChat"", ""icon"": ""/images/profile_placeholder.png"", ""click_action"": ""http://localhost:5000"" }, ""to"": ""YOUR_DEVICE_TOKEN"" }"      https://fcm.googleapis.com/fcm/send

その他

1行にまとめる必要は特にないけど、cmdで^使ってやっても、powershellで`使ってもうまくいきませんでした。
問題が重なって特定が面倒くさくなって1行にまとめました。

さっさと諦めてcodelabに書いてある通り、SaaSのcurl使うのも手だと思うけど、ServerKey公開するの危険だから、refreshしてねって書いてあったので、ちょっくら戦ってみました。

Windowsの環境でこれやってる人って絶滅危惧種何だろうなー。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?