Get real-time notification from Facebook for user updates - php

I am building a website app using Facebook PHP API. My current scenario is I want my server side to get updates from Facebook when a user of mine app(he already give the access_token) has some updates. e.g.: if the user post a comment, if someone post a comment on his wall, send him a message, I wish in my server side I can get this notification.
I have checked out the graph API's realtime updates, but I didn't get if I can use the realtime updates to do the above tasks. I wonder if someone know if the realtime updates can do this or not.
The second solution would be: since I have the access_token, I can periodically check the information of the user to see if there is any new updates. The disadvantage of this approach is that it puts lot of heavy on my server side.

The real-time updates API documentation says:
"You can't subscribe to these user connections yet: home, tagged, posts, photos, albums, videos, groups, notes, events, inbox, outbox, updates, accounts. We will add support for more properties and connections in the future."
The three examples you listed are all not available at the moment. For now, you will need to poll the Graph API every so often to check. You will want to prompt the user for offline_access extended permission to be able to check this later after they leave your site.

Related

Youtube [Data-API] LiveChat where logged-in user is moderator

I'm trying to work out how i get a list of videos/streams where the user is a moderator for live chat.
This is done in nightbot and fussbot but i can't work out how they do it, it works by you adding the Nightbot channel as a moderator of your live streams chat but im unsure how they get your live stream to watch the chat from them being added as a moderator to the channel. (i'm guessing they are a channel moderator and not a video/stream as they are persistent though all casts)
I have thought it would be in the API docs but if it is i can't find it / not sure what im looking for.
I'm implementing this in PHP and so far i have it now getting stream events id's and your persistent live stream ids but i'm now stuck.
I don't think the API supports a way to retrieve a list of chats where the logged-in user is a moderator. The liveChatModerators.list method requires that a value be set for the liveChatId parameter, and that value must specify a single live chat ID.
I'll caveat the following by saying that I'm not familiar with the apps you mentioned or how they work, so this is just conjecture. Your question describes a third-party app that lets you (or helps you to) manage YouTube live chats. Presumably, to use the app, you must have granted that app permission to manage your YouTube account.
With that in mind, if you set up a live stream through that app, then the app could, while creating the live stream, also use the liveChatModerators.insert method to add its own channel as a moderator to the live stream's chat. Similarly, the app could retrieve your list of live streams and add its own channel as a moderator to any of those live streams. The app could use its own data store to determine whether its channel had already been added as a moderator for any particular chat.
Please post a comment in reply if you don't think I'm understanding your question.

Mass Wall Post to multiple users?

I have a contest App. And many users have installed the app. I have stored the offline_access tokens of these users. I want to send a message to all users of app at the end of contest. What is the best way to do it. Because when I do it in a while loop the page never loads and browser just shows loading animation gif on tab.
You don't even need the user access tokens to accomplish something similar to what you're trying to do.
First off, mass-wall posting is both a violation of the Facebook Platform Policies (specifically IV.2, IV.3), but it's also really spammy and users will react negatively, probably blocking your app and ultimately it may get banned from Facebook. So don't do that.
Instead, you should utilise the intended social channel for notifying users of new content, App to user Requests.
This is pretty simple to do, as per the Graph API docs for apprequests you just make the following API call:
https://graph.facebook.com/USERID/apprequests?app_access_token=APPTOKEN
Where USERID is each user's Facebook ID and APPTOKEN is always your applications unique access token (see the documentation here if you do not know how to obtain one of those). You will also need to include parameters such as message, which you can read more about in the docs.

Post on a users wall on behalf of my app (not the user)

For several years i have managed to sort things out without posting my own question, but by readings others instead. However, after reading over 200 useless posts, i've decided it's time i get some help.
I'm building a facebook app, and what i wan't to do is extremelly simple to explain. I wan't to notify a certain user about some event in real-time. For example, "the tv show you want to watch starts in an hour". Unfortunately, facebook doesn't allow apps to send private messages to users (which was my first choice). The standard way of publishing on a users wall on HIS BEHALF is not good either, because no notification is triggered. Therefore, my idea is to post on his wall on behalf of the app (or any similar action that will trigger a notification).
I know about app requests, but they are not what i'm looking for either, as you can see, they do not match what i want to do.
Also please note that the event may be particular for each user, so making a post or something for EVERYBODY to see is not an option ("Peter, you have dinner with stacy in an hour").
Firstly, i want to know if posting on the apps behalf (or facebook page, or any other idea) is possible.
If it isn't, i would like to see any other ideas to sort this out. Remember, it's extremelly important to trigger the notification.
Thanks for your time reading this, but i have one last request.
Although what i want to do is pretty simple, there are plenty of similar issues being disscused, which may lead to confusion, so please be SURE that you fully understood what i am asking before answering.
Thanks again
What about opening an event and auto inviting the specific user to the event?
Events invites trigger a notification and the only thing you need is the user's email address which you can easily get.
I am not 100% sure if an app posting on your wall initiates a notification*. Although posting to a users wall on behalf of an app is certainly possible.
You can follow the instructions on this link, under the "App Login" title, and with that retrieve the correct access token you need to make calls as your app.
In order to have the functionality you specified, you'll have to request the offline_access permission from your users - this will allow you to post to your users wall even when he/she is not currently in or using your app. (or even logged into facebook)
*
Usually these posts on behalf of an app are user initiated - ie the user pressed "post to my wall."

Posting to User's walls as application using Facebook PHP API

I've been building a web app that uses facebook integration for easier registration/login and notifications for the users. However, for the notifications I want to be able to post to a users facebook wall when something happens on our site.
Really I see two possible problems with doing this. First being that the user will most likely not be logged in to our website when the notification needs to happen. Second I have not found a way to post to the feed using any identity other than the current logged in user.
So to reiterate exactly what I'm trying to do. When some action takes place on my site involving Bob, I want the websites application to post on Bobs wall notifying him of the action as if the application is one of Bobs friends. From some of the things I've seen while researching this, it seems as if facebook might not treat applications like users and I might have to go through a page to accomplish what I want. But really I'm ok with that.
What you need to do is to ask for the offline_access permission. Then you can store their graph id property after they login/authorize to your site's database. Then you just post to that graph id instead of instead of /me. In your case you would then POST a request to the "$user_graph_id/feed" endpoint with whatever parameters you usually have.

Post to multiple user profiles from a Facebook app

I am developing a web application that I want to integrate with both Twitter and Facebook. At a certain time, messages will automatically be published on every user's feed, for both their Twitter and Facebook accounts.
I am currently working on the Facebook component. I know that in order to post to a user's feed on Facebook they must grant my app the publish_stream permission. Suppose I have a database of many users who have granted this permission. I want to publish a message on all of their feeds (visible to their friends). do I need to go through the database one-by-one and do an API call to post the message for each of them? This is the only way I can think of at the moment to do this, and it seems excessive to do this especially as the database gets larger and larger.
Is there a more efficient way to do what I describe?
Thanks.
I say its the only way to do it - anyway - what you say looks like bulk messaging which might be thought as spam from facebook privacy policy point of view. If you want to use facebook's platform to do the spreading of the message, then create a facebook page and make your apps users to like that, otherwise you'll have to do it "by hand" - sending the message to each one of your users. This has a positive side effect - you can personalize the message for each of your user (mention their name, their friends name, etc), making your application more social.

Categories