{"id":921,"date":"2019-03-12T19:00:51","date_gmt":"2019-03-12T10:00:51","guid":{"rendered":"http:\/\/idealive.jp\/blog\/?p=921"},"modified":"2019-03-12T19:41:41","modified_gmt":"2019-03-12T10:41:41","slug":"python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework","status":"publish","type":"post","link":"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/","title":{"rendered":"Python\u3067Firebase Cloud Messaging with Django REST Framework"},"content":{"rendered":"<p>\u3069\u3046\u3082\u3053\u3093\u306b\u3061\u306f<\/p>\n<p>Firebase Cloud Messaging\u3092API\u304b\u3089\u30ad\u30c3\u30af\u3057\u3066\u307f\u3088\u3046\u3001\u3068\u3044\u3046\u304a\u8a71\u3067\u3059\u3002<br \/>\n\u672c\u5f53\u306fLaravel\u3067\u4f55\u3068\u304b\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001<br \/>\n\u3044\u304b\u3093\u305b\u3093Firebase Admin SDK\u306ePHP\u7248\u304c<del datetime=\"2019-03-12T10:38:57+00:00\">\u306a\u3044\uff01\uff1f<\/del>\u3044\u3084\u3001\u3042\u308b\u3093\u3060\u3051\u3069\u516c\u5f0f\u3067\u306f\u306a\u3044\uff08\u30b4\u30cb\u30e7\u30b4\u30cb\u30e7\u30fb\u30fb\u30fb<br \/>\n\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u3055\u3063\u304f\u308aLaravel\u306f\u3042\u304d\u3089\u3081\u3066\u3001\u4eca\u56de\u306fDjango\u3067\u3059\u3002<\/p>\n<blockquote><p>\u30b3\u30c1\u30e9\u306e\u30b5\u30a4\u30c8\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<br \/>\nDjango REST Framework \u3067 Firebase Cloud Messaging (FCM) \u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u9001\u4fe1 API \u3092\u5b9f\u88c5\u3059\u308b<br \/>\n<a href=\"https:\/\/leben.mobi\/blog\/fcm_api\/python\/\" target=\"_blank\" rel=\"noopener\">https:\/\/leben.mobi\/blog\/fcm_api\/python\/<\/a><\/p><\/blockquote>\n<p>\u4eca\u56de\u306e\u74b0\u5883\u306f\u3001\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<p>\u30fbWindows 7<br \/>\n\u30fbPython 3.6<br \/>\n\u30fbDjango 2.1.7<br \/>\n\u30fbFirebase \u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306f\u4f5c\u6210\u6e08\u307f<\/p>\n<p>\u3067\u306f\u3001\u59cb\u3081\u307e\u3059\u3002<\/p>\n<hr \/>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u76ee\u6b21<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#Django_REST_Framework_%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB\" >Django REST Framework \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#Firebase_Admin_SDK_%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB\" >Firebase Admin SDK \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#Firebase_%E3%81%A7%E7%A7%98%E5%AF%86%E9%8D%B5%E3%82%92%E3%83%80%E3%82%A6%E3%83%B3%E3%83%AD%E3%83%BC%E3%83%89\" >Firebase \u3067\u79d8\u5bc6\u9375\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#%E5%AE%9F%E8%A3%85%EF%BC%81\" >\u5b9f\u88c5\uff01<\/a><ul class='ez-toc-list-level-6' ><li class='ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#prjsettingpy\" >prj\/setting.py<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#apiserializerpy\" >api\/serializer.py<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#apiviewspy\" >api\/views.py<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#prjurlpy\" >prj\/url.py<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#%E9%80%81%E4%BF%A1%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B\" >\u9001\u4fe1\u3057\u3066\u307f\u308b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/#%E3%81%82%E3%81%A8%E3%81%8C%E3%81%8D\" >\u3042\u3068\u304c\u304d<\/a><\/li><\/ul><\/nav><\/div>\n<h5><span class=\"ez-toc-section\" id=\"Django_REST_Framework_%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB\"><\/span>Django REST Framework \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>Django \u3067 RESTFul\u306aAPI\u3068\u3044\u3048\u3070\u3001\u3053\u308c\u4e00\u629e\u3067\u3059\u3088\u306d\u3002<br \/>\n\u5049\u305d\u3046\u306a\u3053\u3068\u8a00\u3046\u3066\u307e\u3059\u304c\u3001\u521d\u3081\u3066\u4f7f\u3044\u307e\u3059\u3002<br \/>\n\u3068\u3082\u3042\u308c\u3001pip\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u3059\u3002<br \/>\nVirtualenv\u306a\u3068\u304d\u306f\u3001activate\u3059\u308b\u306e\u3092\u5fd8\u308c\u305a\u306b\u3002<\/p>\n<pre class=\"\">pip install djangorestframework<\/pre>\n<p>\u3054\u53c2\u8003\u307e\u3067\u306b\u3001<br \/>\nDjango REST Framework\uff08\u4ee5\u4e0b\u3001DRF\uff09\u3068\u306f\u3001RESTFul\u306aAPI\u3092\u3044\u3068\u3082\u7c21\u5358\u306b\u5b9f\u88c5\u3067\u304d\u3066\u3057\u307e\u3046<br \/>\n\u30d1\u30ef\u30d5\u30eb\u306aFramework\u3067\u3059\u3002\u3082\u3061\u308d\u3093\u3001Web\u753b\u9762\u3068\u3082\u5171\u5b58\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u30b3\u30c1\u30e9 \u21d2 <a href=\"https:\/\/www.django-rest-framework.org\/\" target=\"_blank\" rel=\"noopener\">Home &#8211; Django REST framework<\/a><br \/>\n\u7a2e\u3005\u89e3\u8aac\u30b5\u30a4\u30c8\u306f\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u500b\u4eba\u7684\u306b\u4e00\u756a\u308f\u304b\u308a\u3088\u3044\u306e\u306f\u30b3\u30c1\u30e9 \u21d2 <a href=\"https:\/\/qiita.com\/kimihiro_n\/items\/86e0a9e619720e57ecd8\" target=\"_blank\" rel=\"noopener\">Django REST Framework\u3092\u4f7f\u3063\u3066\u7206\u901f\u3067API\u3092\u5b9f\u88c5\u3059\u308b<\/a><\/p>\n<hr \/>\n<h5><span class=\"ez-toc-section\" id=\"Firebase_Admin_SDK_%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB\"><\/span>Firebase Admin SDK \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>\u3053\u3061\u3089\u3082pip\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u3059\u3002<\/p>\n<pre class=\"\">pip install firebase-admin<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001Firebase\u3068\u306f\uff1f<br \/>\nGoogle\u304c\u63d0\u4f9b\u3057\u3066\u3044\u308bmBaaS\uff08mobile Backend as a Service\uff09\u3067\u3059\u3002<br \/>\nCloud Messaging\u306e\u307b\u304b\u306b\u3001SNS\u8a8d\u8a3c\u3084NoSQL\u306aDatabase\u306a\u3069\u3001\u30e2\u30d0\u30a4\u30eb\u30a2\u30d7\u30ea\u3092\u4f5c\u308b\u306e\u306b<br \/>\n\u5fc5\u8981\u305d\u3046\u306a\u6a5f\u80fd\u3092\u4e00\u3064\u306b\u307e\u3068\u3081\u305f\u30b5\u30fc\u30d3\u30b9\u3067\u3059\u3002<br \/>\n\u3053\u3046\u3044\u3046\u306e\u3092\u99c6\u4f7f\u3057\u3066\u3001\u3044\u308f\u3086\u308b\u30b5\u30fc\u30d0\u30ec\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u304c\u6210\u7acb\u3057\u3066\u308b\u306e\u304b\u30fc<br \/>\n\u6642\u4ee3\u306f\u9032\u3093\u3060\u306a\u30fc\uff08\u9060\u3044\u76ee\uff09\u3068\u601d\u308f\u305b\u308b\u30b7\u30ed\u30e2\u30ce\u3067\u3059\u3002<\/p>\n<hr \/>\n<h5><span class=\"ez-toc-section\" id=\"Firebase_%E3%81%A7%E7%A7%98%E5%AF%86%E9%8D%B5%E3%82%92%E3%83%80%E3%82%A6%E3%83%B3%E3%83%AD%E3%83%BC%E3%83%89\"><\/span>Firebase \u3067\u79d8\u5bc6\u9375\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304b\u3089\u3001\u79d8\u5bc6\u9375\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002<br \/>\n\u3059\u3067\u306b\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u6e08\u307f\u306e\u5834\u5408\u306f\u305d\u308c\u3092\u4f7f\u3048\u3070\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u65b0\u898f\u306a\u306e\u3067\u3001\u4f5c\u308a\u307e\u3059\u3002<br \/>\n\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u8a2d\u5b9a &gt; \u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-923\" src=\"https:\/\/idealive.jp\/blog\/wp-content\/uploads\/2019\/03\/21.png\" alt=\"\" width=\"1031\" height=\"608\" \/><\/p>\n<p>\u300c\u65b0\u3057\u3044\u79d8\u5bc6\u9375\u306e\u751f\u6210\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u3001\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002<br \/>\n\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u3089\u3001Django\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4e2d\u306b\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<hr \/>\n<h5><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E8%A3%85%EF%BC%81\"><\/span>\u5b9f\u88c5\uff01<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>\u305d\u308c\u3067\u306f\u5b9f\u88c5\u306b\u5165\u308a\u307e\u3059\u3002<br \/>\n\u306a\u304a\u3001\u4eca\u56de\u306fapi\u3068\u3044\u3046\u540d\u524d\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<br \/>\n\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u306f\u3001prj\u3067\u3059\u3002<\/p>\n<h6><span class=\"ez-toc-section\" id=\"prjsettingpy\"><\/span>prj\/setting.py<span class=\"ez-toc-section-end\"><\/span><\/h6>\n<p>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068DRF\u3001Firebase\u79d8\u5bc6\u9375\u306e\u30d1\u30b9\u3092\u8a18\u5165\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"\"> :\r\nINSTALLED_APPS = [\r\n :\r\n'api.apps.ApiConfig',\r\n'rest_framework',\r\n :\r\n]\r\nFIREBASE_CERTIFICATE = 'path\/to\/certificate.json'\r\n :\r\n<\/pre>\n<p>\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u3001\u4ed6\u3082\u7de8\u96c6\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h6><span class=\"ez-toc-section\" id=\"apiserializerpy\"><\/span>api\/serializer.py<span class=\"ez-toc-section-end\"><\/span><\/h6>\n<p>Serializer\u3068\u306f\u3001DRF\u3067\u6271\u3046\u30c7\u30fc\u30bf\u5165\u51fa\u529b\u7528\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3001<br \/>\nDjango\u3067\u3044\u3046Form\u307f\u305f\u3044\u306a\u3082\u306e\uff1f\u3068\u3044\u3046\u8a8d\u8b58\u3067\u3059\uff08\u9593\u9055\u3063\u3066\u305f\u3089\u30b9\u30df\u30de\u30bb\u30f3\uff09\u3002<br \/>\n\u3061\u3083\u3093\u3068\u3057\u305f\u89e3\u8aac\u306f\u3001\u3044\u3064\u3082\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u983c\u308a\u307e\u3059\u3002 \u21d2 <a href=\"https:\/\/www.django-rest-framework.org\/api-guide\/serializers\/\" target=\"_blank\" rel=\"noopener\">Serializers &#8211; Django REST Framework<\/a><\/p>\n<p>\u4eca\u56de\u306f\u3001token, title, body\u3092\u53d7\u3051\u4ed8\u3051\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3001<\/p>\n<pre class=\"\">from rest_framework import serializers\r\n\r\n\r\nclass MessagingSerializer(serializers.Serializer):\r\n    token = serializers.CharField()\r\n    title = serializers.CharField()\r\n    body = serializers.CharField()\r\n\r\n\r\n<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001\u3053\u3053\u3067\u306etoken\u306f\u3001\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3088\u308b\u3068<br \/>\n\u300c\u30a8\u30f3\u30c9\u30e6\u30fc\u30b6\u30fc \u30af\u30e9\u30a4\u30a2\u30f3\u30c8 \u30a2\u30d7\u30ea\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3054\u3068\u306b\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 FCM SDK \u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u308b\u6587\u5b57\u5217\u3067\u3059\u3002\u300d<br \/>\n\u3060\u305d\u3046\u3067\u3059\u3002FCM SDK\u306b\u3064\u3044\u3066\u306f\u3001\u8aac\u660e\u3092\u5272\u611b\u3057\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u3001\u305f\u3060\u30ea\u30af\u30a8\u30b9\u30c8\u304b\u3089\u53d7\u3051\u4ed8\u3051\u308b\u306e\u307f\u3067\u3059\u3002<\/p>\n<h6><span class=\"ez-toc-section\" id=\"apiviewspy\"><\/span>api\/views.py<span class=\"ez-toc-section-end\"><\/span><\/h6>\n<p>ViewSet\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u3066\u3001api\u306e\u5b9f\u88c5\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\nFirebase\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u3093\u306a\u611f\u3058\u306b\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u30b3\u30c1\u30e9 \u21d2 <a href=\"https:\/\/firebase.google.com\/docs\/cloud-messaging\/admin\/send-messages?hl=ja\" target=\"_blank\" rel=\"noopener\">\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u3059\u308b | Firebase<\/a><\/p>\n<pre class=\"\">import firebase_admin\r\nfrom firebase_admin import messaging, credentials\r\nfrom django.conf import settings\r\nfrom rest_framework import viewsets, status\r\nfrom rest_framework.parsers import JSONParser\r\nfrom rest_framework.response import Response\r\nfrom api.serializers import MessagingSerializer\r\n\r\n\r\ndef initialize_firebase_admin_sdk():\r\n    cred = credentials.Certificate(settings.FIREBASE_CERTIFICATE)\r\n    firebase_admin.initialize_app(cred)\r\n\r\n\r\nclass MessagingViewSet(viewsets.ViewSet):\r\n    parser_classes = (JSONParser,)\r\n\r\n    def create(self, request):\r\n        params = MessagingSerializer(data=request.data)\r\n        if params.is_valid():\r\n            initialize_firebase_admin_sdk()\r\n            firebase_admin.get_app()\r\n            notification = messaging.Notification(\r\n                title=params.title,\r\n                body=params.body,\r\n            )\r\n            apns = messaging.APNSConfig(\r\n                payload=messaging.APNSPayload(\r\n                    aps=messaging.aps(\r\n                    )\r\n                )\r\n            )\r\n            token = params.token\r\n            message = messaging.Message(\r\n                notification=notification,\r\n                apns=apns,\r\n                token=token,\r\n            )\r\n            messaging.send(message)\r\n            return Response(params.data, status=status.HTTP_200_OK)\r\n        else:\r\n            return Response(params.errors, status=status.HTTP_400_BAD_REQUEST)\r\n\r\n<\/pre>\n<p>ViewSet\u30af\u30e9\u30b9\u306b\u306f\u3044\u304f\u3064\u304b\u30a2\u30af\u30b7\u30e7\u30f3\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u30b3\u30c1\u30e9 \u21d2 <a href=\"https:\/\/www.django-rest-framework.org\/api-guide\/viewsets\/#viewset-actions\" target=\"_blank\" rel=\"noopener\">ViewSets &#8211; Django REST Framework<\/a><\/p>\n<table style=\"height: 228px;width: 42.1037%;border-collapse: collapse\" border=\"1\">\n<thead>\n<tr style=\"height: 10px;background-color: #1380ed;border-color: #ffffff\">\n<td style=\"width: 20.4048%;height: 10px;text-align: center\"><span style=\"font-size: 12px;color: #ffffff\"><strong>endpoint<\/strong><\/span><\/td>\n<td style=\"width: 23.9221%;height: 10px;text-align: center\"><span style=\"font-size: 12px;color: #ffffff\"><strong>HTTP\u30e1\u30bd\u30c3\u30c9<\/strong><\/span><\/td>\n<td style=\"width: 19.9592%;height: 10px;text-align: center\"><span style=\"font-size: 12px;color: #ffffff\"><strong>\u30a2\u30af\u30b7\u30e7\u30f3\u540d<\/strong><\/span><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"height: 10px\">\n<td style=\"width: 20.4048%;height: 10px\"><span style=\"font-size: 12px\">\u30ea\u30bd\u30fc\u30b9\u540d<\/span><\/td>\n<td style=\"width: 23.9221%;text-align: center;height: 10px\"><span style=\"font-size: 12px\">GET<\/span><\/td>\n<td style=\"width: 19.9592%;height: 10px\"><span style=\"font-size: 12px\">list<\/span><\/td>\n<\/tr>\n<tr style=\"height: 24px\">\n<td style=\"width: 20.4048%;height: 24px\"><span style=\"font-size: 12px\">\u30ea\u30bd\u30fc\u30b9\u540d<\/span><\/td>\n<td style=\"width: 23.9221%;text-align: center;height: 24px\"><span style=\"font-size: 12px\">POST<\/span><\/td>\n<td style=\"width: 19.9592%;height: 24px\"><span style=\"font-size: 12px\">create<\/span><\/td>\n<\/tr>\n<tr style=\"height: 24px\">\n<td style=\"width: 20.4048%;height: 24px\"><span style=\"font-size: 12px\">\u30ea\u30bd\u30fc\u30b9\u540d\/id\/<\/span><\/td>\n<td style=\"width: 23.9221%;text-align: center;height: 24px\"><span style=\"font-size: 12px\">GET<\/span><\/td>\n<td style=\"width: 19.9592%;height: 24px\"><span style=\"font-size: 12px\">detail<\/span><\/td>\n<\/tr>\n<tr style=\"height: 24px\">\n<td style=\"width: 20.4048%;height: 24px\"><span style=\"font-size: 12px\">\u30ea\u30bd\u30fc\u30b9\u540d\/id\/<\/span><\/td>\n<td style=\"width: 23.9221%;text-align: center;height: 24px\"><span style=\"font-size: 12px\">POST<\/span><\/td>\n<td style=\"width: 19.9592%;height: 24px\"><span style=\"font-size: 12px\">update<\/span><\/td>\n<\/tr>\n<tr style=\"height: 24px\">\n<td style=\"width: 20.4048%;height: 24px\"><span style=\"font-size: 12px\">\u30ea\u30bd\u30fc\u30b9\u540d\/id\/<\/span><\/td>\n<td style=\"width: 23.9221%;text-align: center;height: 24px\"><span style=\"font-size: 12px\">PUT<\/span><\/td>\n<td style=\"width: 19.9592%;height: 24px\"><span style=\"font-size: 12px\">update_partial<\/span><\/td>\n<\/tr>\n<tr style=\"height: 10px\">\n<td style=\"width: 20.4048%;height: 10px\"><span style=\"font-size: 12px\">\u30ea\u30bd\u30fc\u30b9\u540d\/id\/<\/span><\/td>\n<td style=\"width: 23.9221%;text-align: center;height: 10px\"><span style=\"font-size: 12px\">DELETE<\/span><\/td>\n<td style=\"width: 19.9592%;height: 10px\"><span style=\"font-size: 12px\">delete<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3044\u3063\u305f\u3093id\u306a\u3057\u306ePOST\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u60f3\u5b9a\u306a\u306e\u3067\u3001create\u3067\u5b9f\u88c5\u3057\u307e\u3057\u305f\u3002<\/p>\n<h6><span class=\"ez-toc-section\" id=\"prjurlpy\"><\/span>prj\/url.py<span class=\"ez-toc-section-end\"><\/span><\/h6>\n<p>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306e\u8a2d\u5b9a\u3092\u3057\u307e\u3059\u3002<br \/>\n\u672c\u6765\u306a\u3089\u3001api\/urls.py\u3092\u4f5c\u3063\u3066\u305d\u3061\u3089\u306b\u30fb\u30fb\u30fb<br \/>\n\u3068\u3057\u305f\u3044\u3068\u3053\u308d\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u76f4\u4e0b\u306eurls.py\u306b\u5165\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"\">from django.urls import path, include\r\nfrom rest_framework import routers\r\n\r\nfrom api.views import MessagingViewSet\r\n\r\nrouter = routers.DefaultRouter()\r\nrouter.register('messaging', MessagingViewSet, 'messaging')\r\n\r\nurlpatterns = [\r\n    path('api\/', include(router.urls))\r\n]\r\n<\/pre>\n<p>\u3053\u3053\u307e\u3067\u3067\u3001\u5fc5\u8981\u306a\u5b9f\u88c5\u306f\u304a\u3057\u307e\u3044\u3067\u3059\u3002<\/p>\n<hr \/>\n<h5><span class=\"ez-toc-section\" id=\"%E9%80%81%E4%BF%A1%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B\"><\/span>\u9001\u4fe1\u3057\u3066\u307f\u308b<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>\u3055\u3066\u3001\u30b5\u30fc\u30d0\u3092\u8d77\u52d5\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"\">python manage.py runserver<\/pre>\n<p>\u3067\u3001\u4e0b\u8a18\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n<p><code>http:\/\/localhost:8000\/api\/messaging<\/code><\/p>\n<p>\u3068\u3001\u3053\u3093\u306a\u753b\u9762\u304c\u51fa\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-939\" src=\"https:\/\/idealive.jp\/blog\/wp-content\/uploads\/2019\/03\/22.png\" alt=\"\" width=\"1022\" height=\"955\" srcset=\"https:\/\/idealive.jp\/blog\/wp-content\/uploads\/2019\/03\/22.png 1022w, https:\/\/idealive.jp\/blog\/wp-content\/uploads\/2019\/03\/22-300x280.png 300w, https:\/\/idealive.jp\/blog\/wp-content\/uploads\/2019\/03\/22-768x718.png 768w\" sizes=\"(max-width: 1022px) 100vw, 1022px\" \/><\/p>\n<p>\u3042\u3068\u306fcontent:\u306bJSON\u6587\u5b57\u5217\u3092\u66f8\u3044\u3066\u3001POST\u3059\u308c\u3070\u30c6\u30b9\u30c8\u3067\u304d\u307e\u3059\u3002<br \/>\n# \u3044\u3084\u3041\u3001\u4e16\u306e\u4e2d\u4fbf\u5229\u306b\u306a\u3063\u305f\u3082\u3093\u3060\u3002<\/p>\n<hr \/>\n<h5><span class=\"ez-toc-section\" id=\"%E3%81%82%E3%81%A8%E3%81%8C%E3%81%8D\"><\/span>\u3042\u3068\u304c\u304d<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>\u610f\u5916\u3068\u3055\u3063\u304f\u308a\u5b9f\u88c5\u307e\u3067\u3067\u304d\u307e\u3057\u305f\u3002<br \/>\nviews.py\u306e\u9001\u4fe1\u90e8\u5206\u3092android\u306b\u5bfe\u5fdc\u3057\u305f\u308a\u3001Web\u306b\u5bfe\u5fdc\u3057\u305f\u308a\u3002<br \/>\ntopics\u306e\u4f5c\u6210\u3001\u524a\u9664\u3092\u5b9f\u88c5\u3057\u305f\u308a\u3002<br \/>\n\u3053\u308c\u3092\u30d9\u30fc\u30b9\u306b\u3001FCM\u7528API\u304c\u3059\u3050\u4f5c\u308c\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>R.TANAKA\u304c\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3046\u3082\u3053\u3093\u306b\u3061\u306f Firebase Cloud Messaging\u3092API\u304b\u3089\u30ad\u30c3\u30af\u3057\u3066\u307f\u3088\u3046\u3001\u3068\u3044\u3046\u304a\u8a71\u3067\u3059\u3002 \u672c\u5f53\u306fLaravel\u3067\u4f55\u3068\u304b\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001 \u3044\u304b\u3093\u305b\u3093Firebase Admin SDK\u306ePHP\u7248&#8230;<a class=\"read-more-link button\" href=\"https:\/\/idealive.jp\/blog\/2019\/03\/12\/python%e3%81%a7firebase-cloud-messaging-with-django-rest-framework\/\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":4,"featured_media":956,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,4],"tags":[],"class_list":["post-921","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","category-python"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/921"}],"collection":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/comments?post=921"}],"version-history":[{"count":30,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/921\/revisions"}],"predecessor-version":[{"id":950,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/921\/revisions\/950"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/media\/956"}],"wp:attachment":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/media?parent=921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/categories?post=921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/tags?post=921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}