facebook API: manage_pages permission is not working - facebook

I want to pull the list of pages from an account by using my App. I took reference from https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.2
I have added few scopes "manage_pages, publish_stream, read_stream, publish_actions, publish_pages" to fb:login-button so that I can pull pages. I have added one more function
function getFacebookPages() {
FB.api('/me/accounts', function( apiResponse ) {
if( apiResponse && !apiResponse.error ) {
console.log('For Facebook pages');
console.log(apiResponse);
}
});
}
to pull pages, but it not pulling pages.
Please help me.

For permissions that aren't the default ones ( email, public_profile, user_friends ) you need in 'Status & Review'(from the menu in your app dashboard) to make a submission for them.
Until your review is completed you could create in your app a TEST app at 'Test Apps' ( again, from the menu in your app dashboard ). If you code using the ids of an test app you don't need the submission for permissions, just specify them in the scope.
This must work, please give more details if doesn't works

Related

App in facebook Require Approval?

Scenario is like this:
I have created an app in facebook say myApp.
I have integrated facebook login in my website say mywebsite.com.
I am intended to fetch user's "education_history" ,"work_history" ,"books" , "music".
I am not asking permissions for writing anything on user's facebook wall.
Here the problem.
I am able to fetch required information from facebook only when I logged in ( myapp created on my account only ) but when someone else try to login to mywebsite.com through facebook then I get only his public profile nothing else.
Why is it so ? What I am missing. All permissions are correct.
Thanks for help
EDITED :
Code for login URl :
// Return facebook or linkedIn login url
public function loginurl(){
// It is facebook
$login_url_params = array(
'scope' => 'email,user_actions.book,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_education_history,user_groups,user_hometown,user_interests,user_likes,user_website,user_work_history',
'redirect_uri' => 'http://localhost/users/store/fb/'
);
$login_url = $this->facebook->getLoginUrl($login_url_params);
echo "<a href=" . $login_url.'>Login</a>';
}
You should get a warning when you authorize some specific permissions as App Admin/Developer, telling you to review them:
Apps requesting more than public_profile, email and the user_friends permission must be reviewed by Facebook before those permissions can be requested from people
HereĀ“s more information about the review process: https://developers.facebook.com/docs/apps/review
Localhost will only work for you, but not for other users. Except you are trying with another user on your computer, of course.

Cannot list Ad Accounts in facebook app

I'm developing a pure-html/js web application (actually I'm using AngularJS; with "pure" I mean: I'm not using any server side technology) which uses a Facebook-Connect button like this:
<fb:login-button max_rows="1" size="xlarge" scope="email,public_profile,ads_management" show_faces="false" auto_logout_link="false"></fb:login-button>
Such button asks for permission: ads_management and basic user data. I'm testing ad-management functionality.
However, I ask two queries to facebook inside a controller:
$scope.fetchData = function() {
FB.api('/me', function(response){
$scope.$apply(function(){
console.log("InApp::fetchData()");
console.log(response);
console.log("~InApp::fetchData()")
});
});
};
$scope.fetchAccounts = function() {
FB.api('/me/adaccounts', function(response){
$scope.$apply(function(){
console.log("InApp::fetchAccounts()");
console.log(response);
console.log("~InApp::fetchAccounts()");
});
});
};
$scope.fetchAccountData = function(account_id) {
};
$scope.fetchData();
$scope.fetchAccounts();
For narrow-purposes I just printed the contents of a controller. Assume such controller exists, requires the person is logged in Facebook, and the user is currently logged in.
My Issues are:
The Login button does not update the page when I login. This is because no onlogin= was put. Question: How can I assign such attribute in an Angular way? (i.e. the handler coming from the scope).
$scope.fetchData is successfully executed. However, $scope.fetchAccounts is not. I'm asking this because I included the ads_management permission in the button. Question: What am I missing? (error: code: 10
message: "(#10) You do not have sufficient permissions to perform this action"
type: "OAuthException"). Edit - Additional notes: I deauthorized the application in my account, and reauthorized it: It never asks me the ads_management permission in the popup dialog.
The first question, no idea. The second question, your app is not whitelisted for Ads API usage. Look into the Ads APi documentation on how to request access.

Facebook public posts I make using the Open Graph API are not seen by friends

I'm making a simple Facebook app that posts updates to the user's timeline using node.js and Facebook's Open Graph API. Even though I can see the posts I make using the OG API on my timeline (and it has the globe icon identifying that it's a public post, see pic below), none in my FB friend network can see it.
Here's a screenie of a public post I made via OG API showing up on my timeline, along with a post from a 3rd party app (Pool practice) for comparison:
Now here's the screenie of my friend's timeline showing only the Pool Practice post, the post from my app is nowhere to be seen...
I've checked the app settings and permissions as well as the OG API options, but haven't seen anything that points to how I can solve this problem. Here's the node.js code I'm using to post the updates:
// app permissions set to 'publish_actions' and 'publish_stream'
// I do the auth dance here to get the access_token and store it in session as fb_token
var request = require( 'superagent' ); // module from TJ Holowaychuk similar to "request"
request
.post( 'https://graph.facebook.com/me/feed?access_token=' + req.session.fb_token )
.send( { message: 'posting via node.js' } )
.set( 'Content-Type', 'application/x-www-form-urlencoded' )
.end( function( response ) {
log( response );
});
The code above works and the post shows up on my timeline, but no one else is able to see it.
Anyone know a way out of this?
you need to submit each action for Facebook validation before your friends can view it. Only users defined as developpers for the app are allowed to view those timeline messages.

How to post to a Facebook Page (how to get page access token + user access token)

I am trying to work out how to post to a Facebook page wall, when using my app as a different Facebook User (who is not the Page Administrator).
I get a range of error messages while testing:
Exception: 200: The user hasn't authorized the application to perform this action
The page administrator has visited the app and accepted the following permissions: publish_stream, manage_pages, offline_access
Here is the code I plan to use:
// Insert Page Administrators ID here
// This user is not the same user that is currently logged in and using the app
// This user is the page administrator who has authorised:
// - manage_pages
// - offline_access
// - publish_stream
$user_id = '123456789';
// Insert Page ID here
$page_id = '123456789';
$accounts = $facebook->api('/'.$user_id.'/accounts');
foreach($accounts['data'] as $account)
{
if($account['id'] == $page_id)
{
$page_access_token = $account['access_token'];
echo "<p>Page Access Token: $page_access_token</p>";
}
}
// publish to the wall on your page
try
{
$result = $facebook->api(array( "uid" => $page_id,
"method" => "stream.publish",
"access_token" => $page_access_token,
"message" => $message, ));
}
catch (FacebookApiException $e)
{
error_log('FB Error: Could not post on Page Wall. Page ID: ' . $page_id);
error_log('FB Error Message: ' . $e);
}
Note: There may be PHP errors in the code above, as I just spliced it on the fly, but its not so much the PHP errors I need correcting, but more my logically understanding of how I am meant to go about this process.
PROBLEM:
I can't access the $user_id/accounts information without an active user access token for the Page Administrator.
The end result that I'm trying to achieve is:
1.) A normal FB user goes to the app and submits a form
2.) The app posts a message on a FB Page wall, which is not owned by the FB user, but has previously been authorized by the Page Administrator with the following permissions manage_pages, publish_stream and offline_access
Q1. Since the Page Administrator has accepted the appropriate permissions, why can't I just generate an active user access token, without the actual Page Administrator user logging into the website?
Q2. Is there a way I can get the equivalent of /$user_id/accounts for the Page Administrator user_id, when logged into Facebook as a different user (which is why I do not use /me/accounts)?
Q3. Please confirm that my understanding of needing the page access token to post to the page wall is correct (or do I need the user access_token for the Page Administrator - see Q1)?
Q4. Anyone have a handy resource on what each type of access_token can actually access?
If you need any more information, please let me know.
I've spent the last few days working on this and I'm stuck.
Thanks!
You can ask the page admin for manage_pages along with offline_access. I do this in my production app to be able to post scheduled postings onto the pages' walls.
Nope. Not possible. That's what asking permissions is all about. And why not everyone gets to administer everyone else's pages. Could you image if you could administer anyone's page without them granting you access?!?
To post to the page as the page, you need a page access token. To post to page's wall as a user, you need a user access token.
Yes, please see: https://developers.facebook.com/docs/reference/api/permissions and https://developers.facebook.com/docs/authentication/
If you have further questions about any one of these, please start a new question. It's not really fair to users of stackoverflow to be hit with 4 questions in one and then to be asked followup questions to each of those.
I have done in Django:
Step to get Page_access_token:
facebook_page_id=360729583957969
graph = GraphAPI(request.facebook.user.oauth_token.token)
page_access_token=graph.get(facebook_page_id+'?fields=access_token')
This way you can get Page access token.
You can check this thing on Fb GraphAPIexplorer:
http://developers.facebook.com/tools/explorer
GET URL: fb_page_id?fields=access_token
for example: 360729583957969?fields=access_token
that will give you page_access_token

Facebook account delink or deauthorize facebook app and check status of linking from facebook app

My website application having feature login with Facebook login. And for which my app is present on Facebook. Login with facebook is working fine.
But application have feature of linking and unlinking facebook account to Facebook app.
How to check FB account is linked with specific FB app or not?
And how to unlink FB account from specific FB app if linked (On that user's request )?
("Linked" means we select "Allow" to FB app on request)
With the new Graph there is a documented way to deauthorize (I've tested it in the Graph API explorer and it works). Send an HTTP Delete command to "me/permissions" with a valid access token. Not only will it invalidate the access token, but it also removes the app from the user's list of auth apps. This requires the user to authorize the app again (going thru the permissions screens) to use it. Happy coding!
Please note Facebook in the process of deprecating the REST API, and have adding equivalent support to the Graph API User object for "auth.revokeAuthorization" method.
//$this->facebook is facebook object
//$userid is of logged in user or can be written hardcoded.
For checking linked in or not by making api call.
$user_id = $this->facebook->getUser();
$result = $this->facebook->api(array(
'method' => 'fql.query',
'query' => "SELECT is_app_user FROM user WHERE uid=$user_id"
));
$is_installed = $result[0]['is_app_user'];
if($is_installed==1) {
echo 'Linked';
}
else {
echo 'Not Linked';
}
For delinking or deauthorization the user by making app call:
$user_id = $this->facebook->getUser();
$access_token=$this->facebook->getAccessToken();
$result = $this->facebook->api(array(
'method' => 'auth.revokeAuthorization',
'uid' =>$user_id,
'access_token'=>$access_token
));
This can easily achieved with simple FQL query:
SELECT uid FROM user WHERE uid = {USER_ID_HERE} AND is_app_user = true
This will return uid of user if he is connected with app and nothing otherwise
Make an API call to /{USER_ID}/permissions with your App access token and it will show if that user has authorised your app
You can also check with the user's access token if you have one.
The response type will be something like this:
{
"data": [
{
"installed": 1,
"bookmarked": 1
}
]
}
There'll be one entry there for each extended permission the user has granted your app and the installed line means they've installed your app
For a user who hasn't installed your app the response will be:
{
"data": [
]
}
You can also use FQL as Juicy Scripter suggests in another answer
Here's how to deauthorize your app using Facebook iOS SDK v4:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
...
NSString *graphPath = [NSString stringWithFormat:#"/%#/permissions", [FBSDKAccessToken currentAccessToken].userID];
[[[FBSDKGraphRequest alloc] initWithGraphPath:graphPath parameters:nil HTTPMethod:#"DELETE"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if ( !error ) {
NSLog(#"Facebook unlinked");
}
}];
Through the Graph API, from the docs (thanks #DMCS):
You can de-authorize an application or revoke a specific extended
permissions on behalf of a user by issuing an HTTP DELETE request to
PROFILE_ID/permissions with a user access_token for that app.
The olds REST API offers you auth.revokeAuthorization. You can read more about that on the auth.revokeAuthorization docs.
Be aware that the REST API will be deprecated in the future, although Facebook doesn't specify when exactly.
I am not aware of any way to get a list of apps a given user is connected to, or see any reason Facebook would make that available. To see if a user is connected to your app, the other answers here should provide you with a couple of ideas.