Skip to content

Instantly share code, notes, and snippets.

@CristalT
Last active May 2, 2018 02:10
Show Gist options
  • Save CristalT/8f71547f70449ef46e2312908aaa25b3 to your computer and use it in GitHub Desktop.
Save CristalT/8f71547f70449ef46e2312908aaa25b3 to your computer and use it in GitHub Desktop.
Cloud Function for Firebase for achive Share content in Facebook
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp()
const firestore = admin.firestore()
exports.fbProductShare = functions.https.onRequest((req, res) => {
const params = req.query
const ref = firestore.collection('products').doc(params.id).get()
ref.then(querySnapshot => {
const title = querySnapshot.data().name
const description = querySnapshot.data().description
const image = querySnapshot.data().image //could be the Firebase Storage Download URL
// Replace this by your own url
const url = `https://yourapp.firebaseapp.com/routeToArticle/id`
const content = `
<html>
<head>
<title>${title}</title>
<meta property="og:url" content="${url}" />
<meta property="og:type" content="article" />
<meta property="og:title" content="${title}" />
<meta property="og:description" content="${description}" />
<meta property="og:image" content="${image}" />
</head>
<body>
<script>
window.location = '${url}'
</script>
</body>
</html>
`
res.status(200).send(content)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment