Facebook mark notification as read using python - python

I have managed to read the unseen count of Facebook notifications, but was wondering if there is way to mark the notifications as read. I'm using the Facebook API for python. I saw a link that someone has posted in this site but it's expired.

You should set the field: unread=0 in order to mark a notification as read:
import facebook
graph = facebook.GraphAPI(access_token)
graph.put_object("notification_id", "", unread=0)
For more info you can refer to this: Graph API Doc for norfications
Let me know if there is any issue.

Related

how to create messaging campaign outside console [duplicate]

In Firebase Console I set up audiences based on various user properties and now am able to send notifications to different user segments via console. Is there a way to do the same by http requests to fcm servers? There should be a trick with "to" field, but I couldn't figure it out.
firebaser here
There is currently no way to send a notification to a user segment programmatically. It can only be done from the Firebase Console as you've found.
We're aware that allowing this through an API would expand the potential for Firebase Notifications a lot. So we're considering adding it to the API. But as usual: no commitment and no timelines, since those tend to change as priorities shift.
This has been a popular request, but unfortunately it is not yet possible. We are looking into this.
Please check Firebase Cloud Messaging announcements for any updates in the future.
You can try with topic subscriptions. It is not perfect solution but the best for me at this time.
{
"to": "/topics/audience1_subscription"
"data" : {
"title" : "Sample title",
"body" : "Sample body"
},
}
Yes. No solid solutions are available as of now but I have a workaround solution for it. Which is not able to handle every scenario but it will get the work done.
For that, you need to figure out the audience within the app and you need to segment them with topics. Then you can send a push notification for that particular topic via API.
Let's take an example.
Send notifications to users who didn't open the app in the last 7 days
Subscribe to a topic name "app-open?date=09-21-2022"
each time user opens the app. Just unsubscribe from the topic of the last app opened and subscribe to a new topic with the current date.
Then you just need to build a topic string based on the current day - 7 to send.
And you can create multiple topics for the same user for different behaviors and use them as topics to send push notifications via API to segmented users.
As there is no limit on topics per user or topics per project. You can create as many as topics you want and use them as your need.
Yes.There is trick with the "to" field as mentioned in below.
web URL is: https://fcm.googleapis.com/fcm/send
Content-Type: application/json
Authorization: key="YOUR_SEVER_KEY"
JSON DATA FORMAT:
{"to": "USER_FIREBASE_TOKEN",
"data": {"message": "This is a Firebase Cloud Messaging Topic Message",}
"notification": {"body": "This is firebase body",}}";

How do I scrape a multiple YouTube channel's display name, creation date, and subscriber count?

I am working on a project that scrapes multiple YouTube channels display name, creation date, subscriber count, and view count. I need help creating this project because I can't seem to find anything about it. I have a YouTube API Key and I just can't seem to find anything about this.
It's a little hard to work with the sample code that the YouTube api shows. Use the curl section. Then send a request to the link that shows and use the information. for example send http request to this:
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=[Channel ID]&key=[Your API]
and this address give you JSON file and you can get what you want!.
for example you can see subscribe count from channel list section in youtube api document. like this image.
you can find other things with this way!. good luck :)
also you can use this.
i'm making sample for you.
def subscribeCount(channel_id):
API = f"https://youtube.googleapis.com/youtube/v3/channels?part=statistics&id={channel_id}&key=[Enter Your Api Key]"
json_data = requests.get(API).json()
subscribeCount = json_data['items'][0]['statistics']['subscriberCount']
return subscribeCount
this sample need channel id(Like all other sections xD). and api key you Which you got from the google developer console.It then shows you the number of subscriptions to a channel. The rest of the sections work the same way.
Read the following article for more information.
How to Use the Python Requests Module With REST APIs

using pagination in facepy with facebook graph api

I am trying to get info for every user who liked a post within a given timeframe. As such, I am using facepy in oder to get the data from the facebook api. Now I need to now how I can paginate the data I receive from the api, however i cant get it to work. I've been looking for different solutions that use the facebook sdk, however i cant get them them to work either.
My code so far looks as follows:
graph_data = graph.get('me/posts?fields=likes',since=sTime, until=uTime)
for info in graph_data['data']:
while True:
try:
for comment in info['likes']['data']:
print comment
info =requests.get(info['likes']['paging']['next']).json()
except KeyError:
break
I receive as output the people who liked each post within the timeframe, however I realize that this list does not include all the users who liked (as i can see more on facebook)
Thank you very much!

API General Understanding in regards to Python Gmail-api

I just got started programming a year ago (on and off) and I am trying to save an attachment to a folder offline from my personal GMAIL account.
I was advised to use :
https://developers.google.com/gmail/api/quickstart/python
I set up the
I authenticated the my account and now am trying to get comfortable with this tool.
There are some initial questions that I have
What is User ID ?
is this my email ( tttt#xxxx.xxxx)
or someone else's email (ppppp#yyyy.yyy)
How do I get a email ID's ?
These questions stem from ...
GET https://www.googleapis.com/gmail/v1/users/userId/messages/messageId/attachments/id
from the page :
https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get
Again I am just learning from a beginner place..
Thanks
Just use "me" as the userId as it says in the doc.
To get a messageId first you have to search (list) messages, using something like:
resp = gmail.users().messages().list(userId="me", q="has:attachment subject:'foo bar' before:"2014-01-05").execute()
you can then iterate through the 'messages' in that resp and
gmail.users().messages().get(userId="me", id=message['id']).execute()
The Gmail API guides are quite helpful, take a look at them, for example:
https://developers.google.com/gmail/api/guides/filtering

Can someone provide a simple Python example for Twitter status updates?

I'm having problems to find a simple python twitter oauth example which shows how to post a user status on Twitter. Could you help me?
Check out Mike Knapp's library on GitHub.
Nice and simple, no install needed.
Here's an example that will get you authed with Twitter using rauth.
After that point all you'd have to do to update the authenticated user's status is:
r = session.post('statuses/update.json',
data={'status': 'Updating my status from the cmd line.'})
print r.json()
(You only need to care about the code up until you retrieve your authenticated session object, i.e. line 20.)
Hope this helps!
Edit
You will need to get your own consumer_key and consumer_secret for this to work because the rauth demo app does not have write permissions, for obvious reasons. So you'll end up with this response if you try to run the modified script without updating the credentials:
{u'request': u'/1/statuses/update.json', u'error': u'Read-only application cannot POST'}
Ensure your application is allowed to write and it should work as expected.
Take a look on tweepy: http://code.google.com/p/tweepy/
Have you checked out http://github.com/simplegeo/python-oauth2 ?
Matthew A. Russell has written an excellent book on this, Mining the social web. Take a look at his excample source for OAuth to twitter. The code is available here, and i recommend his book also, covering not only twitter, but facebook and linkedin aswell.
The code is found here: OAuth to twitter and collect friends id's
Good Luck
Here is a simple twitter oauth example I wrote as a blog sometime ago. Hope this helps.
If you're refering to http://code.google.com/p/python-twitter/ ..
On that page it is documented as
api = twitter.Api(consumer_key='consumer_key', consumer_secret='consumer_secret', access_token_key='access_token',
access_token_secret='access_token_secret')
To see if your credentials
are successful:
print api.VerifyCredentials() {"id": 16133, "location": "Philadelphia", "name": "bear"}
That works. Ofcourse, your consumer key should never be human-readable in your application. But it would work even if it was.
*-pike
I've written an extremely simple twitter client (which is just for tweeting).
The source isn't the cleanest around, but the entire thing (including UI) is under 200 lines, so you should be able to extract anything you need from it:

Categories

Resources