Can I transform a user-id to PSID? - Facebook API Graph - facebook

Context: I'm building a webhook with NodeJS to get events from Facebook Page with my Facebook App. These events are: feed, mention (when a user tags the page on his wall) and message. I can get all events without problem. In all events I need to identify the user who write. When the users write a post or message in the page I get an ID (PSID) but when the user write a post on his wall tagging the page I can't get PSID, this is obvious because he isn't in the page scope. The only I get from this event is user-id from post-id.
I have tried the following:
I used this endpoint GET: /<user-id>/ids_for_pages as indicated in the documentation. This doesn't work for me because I would need that the pages are in my business administrator and this isn't possible because I need this webhook to manage many pages to many companies.
I used this endpoint GET: /<psid>?fields=name,id for events of type feed and messages (from Messenger) into the page but this gives me only PSID again.
Note: In my DB I save long-lived token of my page, ASID of the site owner and Page ID when my user does the login in the UI.
My questions:
Is possible transform user-id to PSID?
Can I get user-id through the PSID?
If you have a better idea to unify IDs when is the same user, I would like to know it. If this isn't possible I would also like know it.
My Goal: Each user event goes to the same case for the same user in my API, for this reason if the user is the same when tags the page and/or write a message in the page the idea is to identify him like same user and not like new case.

Related

RestFB - How to publish a post to different user's page using RestFB API

I am trying to publish a post as a user to a Page.
say I am a User A, and I want to publish a post in the Page of User B.
How do I implement it Using RestFB, can someone please help me.?
Also, am able to publish post to my page, but when I try using other page's pageToken am getting an error message Posts where the actor is a page cannot also include a target_id
say I am a User A, and I want to publish a post in the Page of User B.
You can't do that any more via API.
It used to be possible to post to a page, so that it would show in the "visitor's posts" section - but that required publish_actions permission, which has been removed a while ago.
You can now only post to pages you have admin access to.
(Assuming by "page" you actually meant a Facebook Page - not a user profile? But posting to the latter is not possible any more via API either, not even to your own.)

Facebook Bot: Message Mentioner

I'm trying to build a bot that would message anyone who mentions (#PageName) it. I have set up the mention webhook for my bot so that whenever anyone mentions my page in a comment or post, I receive a notification. Unfortunately, Facebook doesn't make it easy to message the person who mentioned my page, since there are different page IDs and messenger IDs. I am able to fetch the user ID from the mention by fetching the from field from the graph API, but is it possible to convert this user ID to a messenger ID so that I may actually message the user?

How to monitor new likes on Facebook page with WebHooks?

I have some questions regarding the Facebook WebHooks.
1)I would like to get notified every time a fb page gets a new like/post etc. I understand this is the feed field. I assume I have to be the facebook page admin for this?
2)What is the exact body of the update object that I will receive in this case? Will it contain information about the liker? Say his/hers email?

How to get post ID of Facebook shared URL, or how to get all posts shared via Facebook app?

Goal
My goal is for a user to share something he created on my site to Facebook, and for me to display all comments on my own page using the Facebook comments plugin.
So my ideal flow would be:
User creates content with example id vjrjf834fdkfj, and shares using public URL http://example.com/vjrjf834fdkfj/.
User shares this URL on Facebook via my Facebook app ID. The post ID is 1234567.
I get this post ID. (This is what I need help with)
I store this in my database.
Whenever a visitor visit the page http://example.com/vjrjf834fdkfj/ I look up in the database what the post ID is (1234567 in this example), and call the Facebook comments plugin using this post ID.
What I tried
Attempt #1
First failed attempt: read the post_id field of the FB.ui callback but this response is typically empty because Facebook says that:
Only available if the user is logged into your app using Facebook and
has granted publish_actions. If present, this is the ID of the
published Open Graph story.
My user is not always logged into my app via Facebook, because he can also create a normal account.
Attempt #2
So my next attempt was to get a list of all posts of this app by calling the Graph API. I have a "basic" app with the "Website" platform set to my website URL (www.example.com). Given this list I might filter this on the relevant URL and voila, get the post ID for the right URL.
I can create an access token and call https://graph.facebook.com/v2.8/{app-id}/objects?access_token={token}, but this gives an error The parameter type is required. And when I try to get a list of object types by calling the /object_types endpoint, I get an empty list.
Attempt #3
I also played a bit with creating a Page Tab but the documentation makes no sense to me as to how that would apply to my case. I ended up with two extra pages, all empty, and not what I want. However, I could live with an extra page on my Facebook page showing a list of all posts that have been shared (so these posts would appear here and on my user's timeline).
Questions
So:
Why is this object_types list empty? I expect that something like "post" would show up here, allowing me to get a list of all posts associated with this app ID.
If this is not possible, how can I still achieve my end goal?
Thanks.

List Facebook Page events on website for a Venue using FQL or Graph API

I am helping out a friend with a site for a venue that lists all events on FB with a location, ticket URI, time, etc.
I have found lots of info on how to get the data, but what I am unclear on is how to get public events without being logged in to FB.
What type of tokens do I need to have a website simply pull events data and display it to visitors?
Basically, what I am attempting to do is show a set number of upcoming events and assume that the visitors to the site are not logged in to FB.
On this page, https://developers.facebook.com/docs/reference/fql/event, it says this:
Permissions
To read the event table you need:
a generic access_token for public events (those whose privacy is set to OPEN)
a user access_token with user_events permission for a user who can see the event for non-public events
an app access_token with user_events permission (for non-public events, must be the app that created the event)
a page access_token with user_events permission (for non-public events, must be the page that created the event)
I am not looking to get help with the code really, I am just having trouble figuring out how the access/auth process works.
It appears FQL may be the best option so I can do queries based on date ranges, but alas, I am stuck on the access/auth/token part.
What do I need to have in place to be able to list a Page's events on a 3rd party site?
If anyone has any advice there, I would appreciate it. Thanks.
Just to explain to others, you cannot get ALL the events in the city by graph search. You need to refine it either by user details or some other metric.
I figured it out.
This question helped, but was not correct and there is a syntax error in an answer:
Get Facebook events from public fan page
From what I found, you need to become an FB developer, create an app, get an ID and secret.
Use the SDK (PHP in my case), and this question had a good example of returning the list I want:
Link from ticket_uri is opening a blank page
I am having the same issue though of getting blank pages on the ticket link if the user is not logged into FB.
But my original issue is solved.