Can't find notifications in firebase console after push notification in pyfcm - python

I'm working on a project where I have to push notifications using pyfcm. I created a firebase project and I took the api key and created an FCMNotification like this :
from pyfcm import FCMNotification
push_service = FCMNotification(api_key="my api key")
Then I create a message and sent it to an already subscribed topic
data = {"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification"
}
}
r = push_service.notify_topic_subscribers(topic_name="user-17", data_message=data)
On this side everything works fine I get the following success message
{'multicast_ids': [], 'success': 1, 'failure': 0, 'canonical_ids': 0, 'results': [], 'topic_message_id': 8479629199217820144}
but in firebase console at https://console.firebase.google.com/u/0/project/project_name/notification it doesn't show the notifications sent by fcm. Although the notifications pushed from postman are being shown.
Please if you can guide me through this I'd appreciate it thanks.

Related

How to enable the Google Firebase notification analytics in Django Python using PyFCM?

We are using the PyFCM module to send the notification via google firebase and somehow the notification analysis report's data is missing in the report section of the GCP firebase console.
Can someone know how to enable the notification analysis on firebase? As we want to know the details of the notification being sent, received, and opened.
We need to add the analytics_label with every notification being sent to firebase and for PyFcm using Django you can pass the analytics_label in the fcm_options given below:-
from pyfcm import FCMNotification
push_service = FCMNotification(api_key=FCM_SERVER_KEY)
registration_ids = ['user_mobile_token_key']
data = {
"body": "test body,
"title": "title,
"priority": "high"
}
extra_kwargs = {'**fcm_options**': {
'analytics_label': 'notification-label'}}
result = push_service.multiple_devices_data_message(registration_ids=registration_ids,
data_message=data, extra_kwargs=extra_kwargs)
print(result)

Python google api reading with urllib and json

My Code is very short but it is not working but in youtube videos it works
import urllib.request
import json
key = "AIzaSyCyTALBjNAEp-Vr5GkilEnLzH0y1Tw6SC4"
data = urllib.request.urlopen("www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=pewdiepie&key="+key).read()
subs = json.loads(data)['items'][0]["statistics"]['subscriberscount']
print(subs)
You need to create you own API key
https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=pewdiepie&key=AIzaSyCyTALBjNAEp-Vr5GkilEnLzH0y1Tw6SC4
shows
"error": {
"code": 403,
"message": "YouTube Data API v3 has not been used in project 195563281908 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=195563281908 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"errors": [
{
"message": "YouTube Data API v3 has not been used in project 195563281908 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=195563281908 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"domain": "usageLimits",
"reason": "accessNotConfigured",
"extendedHelp": "https://console.developers.google.com"
}
],
"status": "PERMISSION_DENIED"
}
}
Here you can find how to create own API key:
https://developers.google.com/youtube/v3/getting-started

Firebase Auth + Python backend

I am going to use Firebase Auth and Database modules to create my web app. However, not all things that I want my app to do is possible to achieve on only front end. So I want to also use backend with Python's Bottle framework to handle requests and Pyrebase to get access to Firebase Database.
Let's say that after logging in I need to go to mainpage and see personalized content, for example my notes. They are structured this way in DB:
{
"notes": [{
"id": "1",
"title": "X",
"author": "user1"
},
{
"id": "2",
"title": "Y",
"author": "user2"
} and so on... ]
}
So how it's possible to implement showing only my articles on main page?
I understand that I need to filter my notes based on author value, but how to let Bottle understand who is currently logged in?
I've read there, that I should somehow send unique token to backend server to authenticate current user, but how to do that? Inserting Token in every link as GET parameter seems to be silly, but I see no other way to implement that.
Start by organizing your database so that each note becomes a child object:
{
"notes": {
"id1": {
"id": "id1",
"title": "X",
"author": "user1",
},
"id2": {
}
}
}
Then this particular interaction can be implemented entirely in the client-side. Just execute a query to filter the notes you want. For example in a JS client:
var uid = firebase.auth().currentUser.uid;
var query = ref.orderByChild('author').equalTo(uid);
// Listen for query value events
If you want to run this on a backend server, and you want to ensure that only logged in users are allowed to execute it, then you must pass the ID token from the client app to the server on each request. Here's how to implement the server-side logic using the Python Admin SDK:
import firebase_admin
from firebase_admin import auth
from firebase_admin import db
token = '....' # Extract from the client request
try:
decoded = auth.verify_id_token(token)
uid = decoded.uid
ref = db.reference('path/to/notes')
notes = ref.order_by_child('author').equal_to(uid).get()
# Process notes response
except ValueError as ex:
print(ex)
# Send error to client

Adding attachements to slacker chat message

I'm trying to post a message using slacker python api for Slack messages
I'm not able to attach a link to my messages as my code below :
attachments = [title, link_to_events, "More details"]
print type(attachments) # this is a list
slack = Slacker(slack_api_token)
# Send a message to #general channel
slack.chat.post_message(slack_channel, message, attachments=attachments)
In the slacker code, it looks like we are looking for a "list" type of variable:
https://github.com/os/slacker/blob/master/slacker/init.py
line 241:
# Ensure attachments are json encoded
if attachments:
if isinstance(attachments, list):
attachments = json.dumps(attachments)
return self.post('chat.postMessage',
data={
'channel': channel,
'text': text,
'username': username,
'as_user': as_user,
'parse': parse,
'link_names': link_names,
'attachments': attachments,
'unfurl_links': unfurl_links,
'unfurl_media': unfurl_media,
'icon_url': icon_url,
'icon_emoji': icon_emoji
})
is there a problem with my code ?
fyi : this is what i've found in the slack api documentation https://api.slack.com/custom-integrations :
{
"text": "New Help Ticket Received:",
"attachments": [
{
"title": "App hangs on reboot",
"title_link": "http://domain.com/ticket/123456",
"text": "If I restart my computer without quitting your app, it stops the reboot sequence.\nhttp://domain.com/ticket/123456",
}
]
}
All right i've found it,
I need a list of dicts
one_attachement = {
"title": "App hangs on reboot",
"title_link": "http://example.com/ticket/123456",
"text": "If I restart my computer without quitting your app, it stops the reboot sequence.\nhttp://example.com/ticket/123456",
}
attachements = [one_attachement]
slack.chat.post_message(slack_channel, message, attachments=attachments)

YouTube api Error

I am a little confuse! I am trying to develop a script that can pull youtube video id in python. So I went ahead and set up my youtube API key.I use this page to generate the URL.
https://developers.google.com/youtube/v3/docs/search/list
This page generated a sample JSON table with the video ID. But when I put this url in my browser
https://www.googleapis.com/youtube/v3/search?part=id&q=gullybop&key={YOUR_API_KEY}
and yes I filled in my api. I expected to get back a JSON table with the vid ids but I get this instead
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
I don't think my API key is invalid
I expected when I put the URL in the browser it would return a JSON table with vid ids but instead I got that error above.
Why am I getting this error ?
Thank you Sean
I got JSON results when I accessed this URL with my API Key. So your API key will be invalid nothing else. Try to create another project in API console and create a key without any referrer no server IP. Only generate 1 key in a project. Dont forget to enable YouTube Data API v3 in API manager.

Categories