How do I get a facebook user's most recent messages with another user? - facebook

I'm working on a web application in which I show the last time the current user (who authenticates with FB and supplies all relevant permissions) user interacted with another user. Example, my ID is 1526632 and would like to find the date of the last message sent between me and another facebook user (either by username, or id #).
I've been reading through their API and it seems this permission existed in version 2.4 of the Chat API but was since deprecated. Is there a new way for developers to get this information somehow?
My guess is this is not possible via the graph API. Assuming this is true, does facebook have unpublished IMAP access to a user's inbox? Or any other creative ways I can do this?

The Chat API is gone, as you have found out already. There is no replacement, what you want to achieve is not possible in any way. The user inbox is off limits now, i´m afraid.

Related

Facebook Messenger Platform: how to get user specific information?

I'm trying the recent released Facebook Messenger Platform and so far so good. Everything worked well and I was able to create a echo bot.
But I'm wondering how I could identify this user that started chatting in my page. For example, when a user started chatting I get a PID user (page specific user id).
Making the follow request to Facebook Graph API:
GET https://graph.facebook.com/v2.6/{PAGE_SPECIFIC_USER_ID}
I discovered that I can just ask for the following fields: first_name,last_name and profile_pic.
So my question is, how could I discover if this user is a current customer of my business page? Is there another way of querying more information (like e-mail and real facebook user id)?
Facebook has updated the messenger platform API (2016-07-01) and introduced a new feature called Account Linking. This can be used to identify a user who has created an account on your website via Facebook Login and you can link the two accounts. Facebook login has its own set of permissions which can be used to get a lot more information via Facebook graph API. You can find the complete list here.
Currently, there's no way to do this. The best way would be to prompt the user to enter their information in chat or give them a link to a mobile login page or some other way of linking their account to the chat.
Messenger Platform 2.0 introduce "ID Matching API" ,that will solve the problem.
https://developers.facebook.com/docs/messenger-platform/connecting-accounts
you can retreive a user information like below using fbmq library https://github.com/conbus/fbmq
# this method will occur when a message received from user
#page.handle_message
def message_handler(event):
user_profile = page.get_user_profile(event.sender_id)
print(user_profile) #first_name, last_name, profile_pic, gender ...

How app_scoped_ids will be used on custom audience after May 1st?

On custom audience, there is the possibility to upload a Facebook ID list for creating an audience... After the Graph API v2.0 migration, when we won't have access to Facebook ID anymore, how can i upload the user id list? Can i use a app_scoped_id based list?
If someone publishes something on my fanpage, and i get his post using Graph API, will i be able to use his id on custom audience? The official documentation don't make itself clear when explaining about the "expiring process" of a app_scoped_id. As far as i understood, when someone authorizes an application, his app_scoped_id will be "permanent", but if there is no user interaction/authorization with my application, the app_scoped_id CAN expire in 24 hours... is that right? If so, how can i use a list of ids on custom audience if they expires?
Thank you!
UPDATE
From https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids:
For users who have not logged into your app, the user ID may change depending on the version of the API that you call. In v1.0 of the API users who have not logged into your app will be referred to by their original Facebook user ID, whereas in v2.0 they will be referred to by an app-scoped ID.
We've added new API endpoints that allow you to tag and invite friends who don't use your app. These APIs return tokens which may be used to generate custom interfaces for tagging and invitations. Those tokens aren't meant to be cachable and we make no guarantees that they will be stable beyond 24 hours from the time the API response containing them was received. They aren't the same as either the IDs used on data for people not logged into your app nor the same as the app-scoped IDs.
You are confusing the app-scoped IDs with temporarily generated IDs. App-scoped IDs will not change over time. Temporarily generated IDs are meant to help with inviting and tagging friends who have not authorized an application and as such they will not remain the same over time.

As a developer, can I browse posts published through my app?

I found the section below on Facebook Developer. Does Facebook provide a way for me to browse the posts by my users, or do I need to store the post ID and write my own dashboard?
It depends which SDK you are using. In general, Facebook does not offer a solution on their own, and if you are using the JavaScript SDK for the postings there is no way to get to the message.
That being said, the only way to get the messages posted via the JS SDK is the following:
The user has to authorize your app
You have to store the access token of the user
You have to store the Post-ID of every post so you can make an API call to get the message
Remember that those user access tokens are valid for ~2 hours only, so you have to use an extended one (up to 60 days valid). After those 60 days there is no way to read the messages anymore, so you would have to store them in your database if you need/want them later. Also keep in mind that the user can remove your app and invalidate the token.
If you are using the PHP SDK for posting (which only works for users who authorized your app), then you can just store the message value in your database because you need to get the message anyway (from a textfield, for example). But be sure to tell the user what you will store, also why and for how long, for privacy reasons.
Summary: The only way to do this (without getting problems with access tokens) is to let the user authorize your app, after every publish you have to use the new post id to get the message with an API call and to store it in your database. This is valid for the PHP SDK and the JS SDK.
Yep, there's no way rightnow, by which you can view the posts published through you're app. The only way you can achieve this is by storing the post_id for every published post, and create a script that will fetch the posts data, when provided with the post_id's

How to detect when friends are online?

I want to create a desktop application that notifies me whenever a specific friend comes online. My idea was to use the chat API, but found out that it doesn't support "presence probes," which I suppose are what I need. Any other to do so?
Your best bet is to use the online_presence field of the FQL user table.
online_presence: The user's Facebook Chat status. Returns a string, one of active,
idle, offline, or error (when Facebook can't determine presence
information on the server side). The query does not return the user's
Facebook Chat status when that information is restricted for privacy
reasons.
To access this information you will need user to grant friends_online_presence permission to your application.

How to use Facebook Application to write a notification to Users

i'm developing an application for a university exam, using Appengine and Gwt (Google products) and i'd like to implement Facebook this way:
- give the ability to a FB user to login to the application through facebook (did this implementing the oAuth2.0 flow, so now i have the user's access token and his permissions)
- since the application is for being notified when a professor publishes some material for his course (this is all handled by appengine), i'd like to notify the user when a professor publishes some material, through a wall post or a note from my application in a way that it writes to the user something about the new published material.
I've been looking through EVERY single resource online, and couldn't find an answer: a lot of similar questions but no answers.
Writing the POST is not a problem, and for the moment i'm trying with the api graph explorer.
I manage to write on the user's wall/note as if he's writing himself or (if the user likes the application) write all the likers a wall post/note (but the same to everyone).
But i don't find a way to send personalized wall posts/notes to every user in response to some specific material published.
FB doesn't allow to do this because is considered spamming?
You can't directly post things to your user's wall as a way of notifying them - wall posts are intended to be things the user posts from within your app (for instance, they find something in your app interesting and choose to share it with their friends, so they click a 'Share' button).
You could try using an App-Generated Request (http://developers.facebook.com/docs/channels/#requests). This will increment the user's Bookmark Counter, and when they click on it they will enter your app and you can show them the latest news.
OR, you could ask for the 'email' permission for your app, and send the user an email notification when something is new.