Giter Site home page Giter Site logo

android-notification-rest-api's Introduction

Hi ๐Ÿ‘‹, I'm Belal Khan

I'm a highly skilled Android Developer with a proven track record of delivering exceptional projects and optimizing app performance.

probelalkhan

probelalkhan

probelalkhan

Connect with me:

probelalkhan probelalkhan probelalkhan probelalkhan probelalkhan probelalkhan simplifiedcoding

Languages and Tools:

android dart express firebase flutter git java javascript kotlin mongodb mysql nestjs nodejs postgresql pytorch sqlite tensorflow unity

Support:

probelalkhan



probelalkhan

ย probelalkhan

probelalkhan

android-notification-rest-api's People

Contributors

probelalkhan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

zakaria-rada

android-notification-rest-api's Issues

Getting error 404 while executing the REST API in Postman

Hello,

I followed all the steps in the video no 15 (https://www.youtube.com/watch?v=pnysHgQvOiM&list=PLk7v1Z2rk4hjM2NPKqtWQ_ndCuoqUj5Hh&index=16&t=0s) but I'm getting

"404

Page Not Found

The specified file was not found on this website. Please check the URL for mistakes and try again.

Why am I seeing this?

This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory." in Postman.

Till 15th video, everything is working fine. REST API is working fine on localhost but it's not working with the web address of the google function. Please check the code
Please help me with this issue, I'll be highly grateful to you.

index.js

const functions = require('firebase-functions');
var {google} = require('googleapis')
var MESSAGING_SCOPE = "https://www.googleapis.com/auth/firebase.messaging"
var SCOPES = [MESSAGING_SCOPE]

var express = require('express')
var app = express();
var bodyParser = require('body-parser');
var router = express.Router();
var request = require('request');
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
router.post('/send',function(req,res){

getAccessToken().then(function(access_token){

    var title = req.body.title;
    var body = req.body.body;
    var token = req.body.token;

    request.post({ 
        headers:{
            Authorization: 'Bearer '+ access_token 
        }, url: "https://fcm.googleapis.com/v1/projects/androidnotification-e44a6/messages:send",
        body: JSON.stringify(


            {
                "message":{
                  "token" : token,
                  "notification" : {
                    "body" : body,
                    "title" : title
                    }
                 }
              }
        )

    },function(error,reponse,body){

        res.end(body);
        console.log(body);
    });
});

});

app.use('/api',router);

function getAccessToken()
{
return new Promise(function(resolve,reject){

var key= require("./service-account.json");
var jwtClient = new google.auth.JWT(


    key.client_email,
    null,
    key.private_key,
    SCOPES,
    null
);

jwtClient.authorize(function(error,tokens){

    if(error)
    {
        reject(error)
    }
    resolve(tokens.access_token)
  

});

jwtClient.authorize(function(error,tokens){

    if(error)
    {
        reject(error)
    }
    resolve(tokens.access_token)
    console.log(tokens.access_token)
});

});
}

exports.api = functions.https.onRequest(app);

firebase.json

{
"hosting":
{

"public": "public",

"rewrites": [
{
"source": "/api/send",
"functions": "api"
}
],
"ignore": [
"firebase.json",
"/.*",
"
/node_modules/**"
]

           }

        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.