GET Facebook wall posts of admin - javascript

What started off as easy as "Let's put all our brand's Facebook posts on our website" has turned out much more difficult.
The situation:
There are multiple admins that manage the Facebook fan page (20+)
RSS feeds no longer seem to work with some brand pages
I have registered an APP ID, and am getting back an access token at an application level like so:
https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=AAAAAAAA&client_secret=BBBBBBBB;
Below are some varying cases and what they return. All examples below assume the access token is retrieved using the URL above
Case 1: /posts
Will return the wall posts of the parent account (the one who started the Facebook fan page), and not the admin's who administer it.
https://graph.facebook.com/PAGE_NAME/posts?access_token=XXXXXXXXXX;
Case 2: /feed
Will return the wall posts by all other users, and NOT the admins or page owners
https://graph.facebook.com/PAGE_NAME/feed?access_token=XXXXXXXXXX;
Case 3: FQL
Will return same results as Case 1, note DDDDDDD = Page UID
SELECT post_id, created_time, message FROM stream WHERE source_id=DDDDDDDD AND actor_id=DDDDDDDD
Now, funnily enough, when I use Facebook's Graph API Explorer (logged in of course), and I call Case 1 above "/posts" I DO get all the posts (including the ones from all page admins and owners). This is exactly what I want!
So why am I here? Because of the access token issue. This is a stream to be used on a website, i.e. there is no requirement for a user to connect to Facebook as we don't need their permissions nor to access their data, which is why I'm using the application access token.

Is manage_pages permission given to your app token? I hope this link helps: http://developers.facebook.com/docs/authentication/pages/

Related

Getting empty list on post reactions. What could be the reason?

I am trying to read reactions on a post using the following graph-api call:
FB.options({version: 'v2.12'});
FB.setAccessToken('EAACEdE7w4Fp85PlhH0NYpZBddHyqkx6XXXX')
FB.api('/765898450131958_1518951084826687/insights?metric=page_actions_post_reactions_wow_total', (res) => {
console.log(res)
});
But I always receive an empty data list. What could be the reason for this? For reference I am using FB module to connect to graph-api.
The acces token I am using is my page-access token
In my case, the facebook app instance wasn't set to live. Once the facebook app instance is live, data array returns user info list with id and name . You can check that out in App Review Settings
Click your app instance -> Go To "App Review" -> Click "My Permissions & Requests".
You will see that there are two approved items. I think these are added or granted by default. But if your app is not live, the two permissions will not be active. That includes basic user information like name and profile picture.
TL;DR - Check if your app is live and also make sure that you are using Page Access Token rather than User Access Token.
From official Facebook API documentation:
On February 5th, 2018, User information will not be included in responses unless you make the request with a Page access token. This only applies to Comments on Pages and Posts on Pages.
https://developers.facebook.com/docs/graph-api/reference/v2.12/object/reactions

Javascript Facebook SDK Add/Delete comment on Users feed. Access Token

I have a web app running on a local server that I can log into Facebook through.
I have been trying to add or delete comments from Posts are made by me and on my timeline.
When I try to execute the FB.api() call I get a failed response saying that I need a Page Access Token. The thing is, I've been looking around a lot and have seen nowhere a mention of a Page Access Token for a specific Persons profile.
Through experimenting I've been able to:
Get a Page Access Token for a non-profile Page that I own
Add/Delete Comments/Posts on that non-profile page
Add/Delete Posts made by the app on my profile
Display all Posts/Comments on my profile
What I want to do:
Be able to delete/add comments on Posts on MY profile
What I've tried:
GET request for {my-id}?field=access_token. I figured that if it worked for a non-profile page, it would work for my profile. It didn't work.
A lot of googling
My Assumptions:
I need a Page Access Token for my own profile if I want to add/delete things that were not made by the app
A Page Acess Token for a profile exists.
Below is an example of a FB.api call that would return a response saying:
"Publishing comments through the API is only available for page access tokens"
FB.api(`${comment_id}`, 'DELETE', function(response) {
console.log(response);
});
I really just need someone to give me some concrete answers.

Is it possible to post to chat.postMessage as any user in a Slack team?

I'm building a Slack integration that is intended to modify some text and then post it to a Slack channel as though the user who triggered the command had said it.
e.g. /makeFace disapproval
#Ben 3:45pm
ಠ_ಠ
I ask for the client permission scope, which adds the chat:write:user permission. But when I hit the chat.postMessage endpoint, it only seems to allow you to post as the user who added the integration because the token it returns seems to be individuated for that user.
I know that giphy, for instance, sends its gif messages as though you are the originator, but I can't find out how they manage it. Is there any documentation for sending messages as other members of the team?
There are 2 ways to achieve this:
A. Overwriting username and icon
When you send a message with chat.postMessage it is possible to set a user name with the property username. The message will then appear as being send by that user (same for icon with icon_url).
However, this is not meant to impersonate real users, so even if you use the same username and icon as the real user the message will have the app tag, so that they can be distinguished from a real user.
Here is an example how it looks like (from a gamer Slack about flying and killing space ships):
But depending on what your requirements are that might work for you.
If you want to use it make sure to also set the as_user property to false (yes, really) and it will not work with a bot token, only with a user token.
See here for more details on how it works.
This also works for the legacy version of Incoming Webhooks, not with the current version of incoming webhooks though. (You can still get the legacy version, see this answer)
B. Having the user's token
Another approach is to always use the token from the respective user for sending the message. In combination with as_user = true messages sent by your app will look exactly as if they would come from the respective user (no APP tag).
To make that happen your app would need to collect tokens from all users on your workspace and store them for later use. This can be done by asking every user to install your app (called adding a "configuration") through the Oauth process (same you use to install your app to a workspace), which allows your app to collect and store those tokens for later use.
Update: This doesn't work. It impersonates the user who installed the app, so it merely seems to work... until another user tries to use it (and they end up impersonating you).
Go to your App's management page. Select "OAuth & Permissions".
Add the chat.write OAuth Scope to your app as a User Token Scope, not a Bot Token scope.
Take note of your User OAuth Token at the top of this page (not your But User OAuth Token).
Call chat.postMessage with
username = user id of the user you'd like to post on behalf of
token = the token from step 3. above
The resulting post will be 100% impersonated. Not just the name and icon as mentioned in other answers, but it'll 100% function as if it came from the user.
I hope this will help those who are still facing this issue.
First give the chat:write and chat:write.customize scope to your bot. The scope chat:write.customize Send messages as #your_slack_app with a customized username and avatar
From "OAuth & Permissions" settings get the bot OAuth token or even bot access token (both will work).
Then set the arguments like the following.
username to specify the username for the published message.
icon_url to specify a URL to an image to use as the profile photo alongside the message.
icon_emoji to specify an emoji (using colon shortcodes, eg. :white_check_mark:) to use as the profile photo alongside the message.
You can visit the docs from here

How to get the posts of the news feed with graph api javascript

I want to get my Facebook news feed in order to filter depending on some options.
But when I ask for permission as below, read_stream is not accepted, I 'm getting "Invalid Scopes: read_stream"
FB.login(checkLoginStatus, {scope:'read_stream,email,publish_actions, user_friends, user_posts '});
Looking around in Internet, I found out that this permission has to be required from Facebook.
Any workaround for that would be much appreciated.
The permission read_stream was deprecated with v2.4. You wouldn't have gotten it granted during Login Review anyway.
Basically, /{user_id}/home endpoint with the newsfeed is no longer accessible. If you want to use /{user_id}/feed, that should work, but this only contains the user's own timeline.
See
https://developers.facebook.com/docs/apps/changelog#v2_4
https://developers.facebook.com/docs/graph-api/reference/v2.4/user/home/
https://developers.facebook.com/docs/graph-api/reference/v2.4/user/feed

Explain the Facebook access_token

This whole Facebook access_token thing is driving me nuts. All I want to do is fetch a user's public Facebook posts.
It used to work by simply doing:
$.getJSON('http://graph.facebook.com/USERNAME/posts?limit=LIMIT&callback=?', function (posts) {
// Posts available in "posts" variable
});
But now I get the "access_token required" error.
Trust me; I've checked the docs, Googled all over and checked similar questions on SO but I'm really hoping there's a more straight forward way of doing this than what I've seen.
Do you really have to create a Facebook App (I don't even have an account), make the user "accept" the app and login etc for this to work?
With Twitter it's just as easy as it used to be with Facebook.
You really have to create a Facebook App (You need to have an account), make the user "accept" the app and login etc for this to work.
However you can search public posts of user (not a specific user) by facebook's public search api.
e.g.
https://graph.facebook.com/search?q=hello&type=post
This will search all posts with hello keyword in it.
Reference ( you need to have facebook account to see this page )
http://developers.facebook.com/docs/reference/api/
Edit (after seeing comments):
If you want to access public posts of your own page. You can pull it without any login from user (but you will need an access_token)
Generate an offline access_token from here,
http://developers.facebook.com/tools/explorer.
Then you can use that token to pull data . Thus no need of logging on by user.
https://graph.facebook.com/wesellwine/posts?access_token=<access_token from graph api explorer>

Categories

Resources