How to post to a facebook page feed from external web site - facebook-graph-api

We have a company-owned web application that should post to our company-owned facebook page.
should be a server-to-server call
the user in our webapplication who makes the post in the webapplication gui, should ideally not have to be a facebook admin for the facebook page.
We have a facebook App that is added to a testpage on facebook, and when I do this API call:
https://graph.facebook.com/PAGE-ID/feed?message=MESSAGE-CONTENT&access_token=APP-ID|APP-SECRET
..the answer I get back is:
{
"error": {
"message": "(#200) The user hasn't authorized the application to perform this action",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "TRACE-ID"
}
}
It seems like I need the publish_pages right, and this right require an App-review (unless users are known and assigned roles in the app), but it says in the review info from facebook, that automatically publishing is not allowed for this right.
We can save a token in database and reuse when posting to Facebook Graph API.
Is this impossible without a facebook user doing a Facebook login in our webapplication?
Should we instead get a long-lived user token from a facebook-page-administrator, and then reuse this when posting, and re-login to facebook client side, before token expire?

Related

How do I get instagram_basic permission during development?

I'm trying to use this endpoint from the Instagram graph api:
GET /ig_hashtag_search?user_id={user-id}&q={q}
Documentation for this endpoint can be found here.
I'm running this GET request:
https://graph.facebook.com/v14.0/ig_hashtag_search?q=coke&transport=cors&user_id=<my_user_id>&access_token=<my_access_token>&q=coke
and get this as response:
{
"error": {
"message": "(#200) Requires instagram_basic permission to manage the object",
"type": "OAuthException",
"code": 200,
}
}.
The user id comes from my instagram account and the access_token that I'm using is a User token generated with "Graph API explorer" and I can see that this token has the scope "instagram_basic" when using the "Access Token Debugger".
I can't understand why this does not work? Do I really need to submit a API review just to test the hashtag endpoint during development?
Please help!
I guess sometimes App review team of Facebook doesn't know what is the usage of the permission so they just decline the submissions randomly. I got that permission like 3 months ago and i checked my app review. I send them this text
We are going to use instagram_basic to read an Instagram account profile's info and media. We will get the basic metadata of an Instagram Business account profile like "USERNAME", "ID", "FOLLOWERS", "FOLLOWING". You can check the Screescast to see how we use the instagram_basic on our app.
Here is what they saw while they do the app review
Also be careful while you send requests, keep in mind to change it to development mode. Some of the endpoints works only in live mode. The API still changes a lot and there are tons of bugs i see in my project. I hope this helps.

How to like on behalf of the user - Facebook Workplace API

While working with the Facebook Workplace API liking an object (post, comment, photo..etc) can be done by passing the Admin Access Token, I'm trying to figure out how to do it on behalf on the user for a feed / comment posted into a group.
The docs mention getting the Page Access Token to perform this action but a Group doesn't have an Access Token & doesn't really solve what I'm going for anyway.
I've tried getting the User Impersonation Token from the API using the Admin Token but posting to the likes graph endpoint results in a publishing error.
POST /https://graph.facebook.com/{COMMENT-ID or POST-ID}/likes
HEADERS: Authorization Bearer "{IMPERSONATION-TOKEN}"
Error Response:
{
"error": {
"message": "(#3) Publishing likes through the API is only available for page access tokens",
"type": "OAuthException",
"code": 3,
"fbtrace_id": "CGpXtFWrwiA"
}
}
Again this works fine using the Admin App Access Token but not on behalf of the user. Also a group doesn't have an access token unlike a regular FB Page.
Any help on this would be great!

How to get userID from access token in Facebook Graph API? [duplicate]

I am developing an android app. I was using a HttpURLConnection to get profile pictures of facebook users. The URL looks like this:
http://graph.facebook.com/?ids=username1,username2,username3&fields=picture&type=square
But now, since v2.2 doesn't let me to get profile pictures of users who are not using my facebook app, it throws an error:
{ "error": {
"message": "(#803) Cannot query users by their username (username1)",
"type": "OAuthException",
"code": 803 } }
I am not interested in using "Facebook SDK for Android". Let's say I use a pop-up webview to authorize my facebook app. What url would let me do the same thing? Is there a simple solution like this:
graph.facebook.com/?app=APP-ID&ids=username1,username2&fields=picture
Since v2.0 of the API, you are not supposed to use usernames at all - and that´s why you can´t query users by their username anymore. The only way to get access to data of a user is by authorizing that user and using the /me endpoint.
Main rule: Forget about users who did not authorize your App, you are not supposed to get any data of those for privacy reason.

Post to Facebook page with Open Graph

trying to figure out why I cannot post to Facebook Page (not profile) with Open Graph API.
I have submitted for review and got approved an action. I have permissions approved, such as:
manage_pages
publish_actions
publish_pages
When I make a post to facebook profile eveything is working fine:
https://graph.facebook.com/me/com-domain:post?access_token={access_token}&method=POST&property={url}&message=test&fb:explicitly_shared=true
The problem appears to be posting to Facebook Page.
First of all I am making request to /me/accounts and getting proper PAGE ID and Page access token.
https://graph.facebook.com/me/accounts?access_token={access_token}
After that, grabing new access token and page id making another request to
https://graph.facebook.com/{PAGE_ID}/com-domain:post?access_token={page_access_token}&method=POST&property={url}&message=test&fb:explicitly_shared=true
And getting result:
{ "error": {
"message": "Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "Ffdsfds" }}
Any suggestions ? Thank you!
After talking to Facebook support it appears that it is not possible to post via custom actions to Facebook Page. Only to profile. Case closed

Facebook Graph API, Unable to post as a page due to permission issue

I have a facebook application, not yet submitted to FB for permission review.
The app is intended to allow user to post and reply to other people's post as their own administrated page.
Upon authorization, the application would request the following permission
Publish action
Publish Pages
Manage Pages
I used my own account, with tester role in the app, to granted all requested permission and verified the result in permission is indeed there in my app settings for the application. I have also verified that my account is an administrator of the page I intend to reply as.
It all seems ok until I tried to post a reply to the API using the page token
https://graph.facebook.com/postid/comments
I receive an error:
{
"error": {
"message": "(#200) You do not have sufficient permissions to perform this action",
"type": "OAuthException",
"code": 200
}
}
I can't think of any reason why the permission is missing. I understand that the three permissions need to be approved by Facebook eventually, but to get approval, I'd need to get my app up running for testing first. Is there anything I'm missing here?