In a previous version of the PHP SDK there was the ability in an App to get the Profile ID of the user that owned the page where the app was installed.
$facebook->get_profile_user()
This was possible without having the end user authorize access to the Facebook App.
However I can't find anything similar in the new JS or Graph API's. The closest thing I could find was the https://graph.facebook.com/<page_id>/admins, however it seems this call either doesn't work, or requires addition permissions:
Access Token:AAADF5PRI7BkBAKSz9Wqfbkuib6JH7WkZCQDZBgLNO10s1ZAMKF7BO7Y3YCVqkYNuCJ9QroWHYYn8n5wC8diPuBDPGsNUS5tDnZAZA6rFSx28VtpvVhUlY
Graph API: /210093142392039/admins
$this->facebook->api('/291231207559006/admins')
( ! ) Fatal error: Uncaught OAuthException: (#210) Subject must be a page. thrown in /html/classes/facebook/base_facebook.php on line 1033
Is this functionality gone? We were using the Profile ID as a key in a datasource, so it'd be ideal to keep this same key, if not we can start storing the page-id instead, however this would the users would have to reinitialize the app..
After September 22, 2011, manage_pages permission is required to do that.
You must request for the manage_pages permission, get the page access_token and then make the admins request with the page access_token.
Please refer to http://developers.facebook.com/docs/reference/api/permissions/ for updated permissions.
Well, I actually had the same problem some time back and found a solution for it. What i was doing was passing the user access token intead of the page access token. I would suggest that you should try something like
$pageIds=$facebook->api('/me/accounts');
$pageAccessToken=$pageIds["data"][1]["access_token"]; //get the access token for page "[1]" over here
and then try
facebook->api('/<page id>/admins', 'get' , array("access_token" => $pageAccessToken));
Related
I am writing application for getting reviews for particular page from facebook. I found that for getting reviews you need to ask user for manage_permission and you will get one token which can be use for further communications.
But, right now manage_pages permission is deprecated since May 2022, what is alternative for getting user page access token to get reviews.
Furthermore, here it says that we can get page access token and page id using get page id. I am passing user id and token which I store using facebook login, but, I am not getting any data related to page.
Thanks.
With regards to your question, you can request for pages manage posts permission.
Read Doc. https://developers.facebook.com/docs/permissions/reference/pages_manage_posts
Based on the doc on Facebook page access token following steps are need to be taken to obtain a long-lived Page Access Token.
Extend the User's Access Token which has the manage_pages permissions
Get the page access token thru the /userId/accounts end point using the extended user access token.
This process is working fine and I am able to obtain and use the page access token properly.
The issue arises when the user grants a new permission to the App - such as 'publish_actions' to allow the App to post on the Page's timeline, the page access token obtained using the above mentioned mechanism does not work properly.
Until about a 6 to 8 weeks ago the new publish_action permission would allow the previously saved page access token to post on the page's timeline without any issue. This feature seems to have broken where I am getting the following error :
{"error":{"message":"(#200) The user hasn't authorized the application to perform this action","type":"OAuthException","code":200
When the access token is debuged using the Facebook debugger tool - it shows that the saved page access token is indeed embellished with the new permission as follows :
App ID XXXXXXXXXXXX : App Name
Profile ID 999999999999 : Page Name
User ID 9999999999999999 : User Name
User last installed this app via API v2.x
Issued 1454463877 (40 minutes ago)
Expires Never
Valid True
Origin Web
Scopes email, manage_pages, publish_actions, public_profile
So although this page token has publish_actions permission it is not able to post on the page's timeline. This has stopped working recently and looking for any other folks who have faced a similar issue and have managed to resolve it.
Btw, I have already tried refreshing the page access token using the newly generated user access_token at the time when the user gives the publish_actions permission. Going the thru the above 2 steps using the new user access token, seem to return the same page access token and it continues to fail to post on timeline...
Any help is much appreciated.
The issue was related to using incorrect permission. Facebook has introduced a new 'Publish_pages' permission which should be used to make posts on business pages. We were using publish_action which was invalid (since v2.3 or somewhere around that - we are using v2.5 of the graph API so it caused a problem).
Facebook responded pretty quickly to our bug report and provided this guidance which helped resolve this issue (I should have posted this answer earlier).
I am building my first facebook app and am facing a issue.
Task : Build a entirely server side application to be used by the admin of a facebook page to post videos/photos on the page. This should not involve having the admin to log in everytime to generate the user acess and page access token.
What I found : Based on the requirement, I found that app tokens can be used for this purpose. This line specifically hints at the usefulness.
App access tokens can also be used to publish content to Facebook on behalf of a person who has granted an open graph publishing permission to your application
I think that using this will be safe since mine is an entirely server side app.
Problem The docs say that:
GET /oauth/access_token?
client_id={app-id}
&client_secret={app-secret}
&grant_type=client_credentials
will give the app token that can be used in place of user access token.
However, I have not been able to do so. Specifically the error encountered is
Error 200 .The user must have accepted the TOS. Since I have already tried publishing content with page access token, I know this is a permission issue.
The following line
a person who has granted an open graph publishing permission to your application.
does not clarify everything. I came across a related question, but the answers seem to be a bit vague.
It would be really great if someone could give me insights about how this can be achieved.
In order to post to a page, you need at least authorize with the manage_pages permission. If you want to post "as user", you need to add publish_actions and use a "User Access Token". If you want to post "as page", you need to add publish_pages and use a "Page Access Token".
Information about how to generate those Tokens:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
The error message with the TOS has been discussed a lot of times already, please go to those threads (or find a lot more with the search function):
(OAuthException) (#200) User must have accepted TOS on C# - Facebook
How come I get a "must have accepted TOS" error for test users with app installed?
facebook long term token "(#200) User must have accepted TOS"
Occassional (OAuthException - #200) (#200) User must have accepted TOS
You cannot post to a Page via an App Access Token. This is clearly stated in the docs at
https://developers.facebook.com/docs/graph-api/reference/v2.3/page/feed#publish
A user access token with publish_actions permission can be used to publish new posts on behalf of that person. Posts will appear in the voice of the user.
A page access token with publish_pages permission can be used to publish new posts on behalf of that page. Posts will appear in the voice of the page.
I'd recommend to use a eternal Page Acess Token, so there's no obligation to renew the User Access Token. Have a look at my answer here:
Post to a facebook page without "manage_pages" permission using php
See
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens
I create a demo application to request photos from facebook. I created an application token like this : 549933848476397|4a584ce5fda19cba2ed6630ed78ba8f4. But when use this request URL https://graph.facebook.com/1417833425116725/photos?access_token={app_id}|{app_secret}. It's does not work. Please help me. Actually When I use user token for this request, It's work ok.
If the Page is restricted somehow (age, location), you can only use a User or Page Access Token to get data like photos of the Page. The App Access Token got no relation to any User, so Facebook canĀ“t detect if the User is even allowed to see the Page.
I am 100% sure the Page is restricted btw, you get an "Unsupported get request" error when trying to access the Page ID directly with the Graph API, and that usually happens when the Page is restricted.
Just try another Page with that exact same App Access Token, for example:
/bladauhu/photos
...works without any problem. Another sign that your Page is indeed restricted.
TL;DR: For this specific Page, you MUST use a User Token or Page Token.
I'm trying to build a website with the following requirements. I need help to see if it's possible at all. This website has a regular login (not Facebook). Upon being logged in, the user has the option to "attach" his facebook account. At this point I save the return user id in the DB. Then, I tried on another computer the following Facebook Graph API call with this user id but it said:
Fatal error: Uncaught GraphMethodException: You can only access the "home" connection for the current user. thrown in /home/public/vendor/facebook/php-sdk/src/base_facebook.php on line 1294
The call:
/{user-id}/home
Appreciate help.
According to the error message you're trying to call /{user-id}/home but are using an access token from a different user -
You can't fetch another user's news feed, only the current user of your app, using their access token
Try {user-id}/feed. If you are not using the accessToken that was generated by the facebook API on the "attach" time, you will be able to get only the public feeds/data. Using the access token that was generated at the "attach" time, you will be able to get data for your app permissions.
About access token
https://developers.facebook.com/docs/facebook-login/access-tokens
How to use the graph api
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0