Not able to set user_friends permission in facebook app - facebook

I created a facebook app, this app needs to ask for user_friends permission.
But when I give this permission in admin settings section under permission, it doesn't change the permission for my app other then this permission I can set.
Why this specific permission (user_friends) can't be set? Is there anything extra I need to do to set this permission?

To ask for additional permission like user_friends you need to add the permission as scope when generating the login URL, instead of adding it under permissions section of the admin settings page of your app.
If you are using PHP for your development, then you be to provide the scope as a parameter to the getLoginUrl ().
$params = array(
'scope' => 'read_stream, friends_likes',
'redirect_uri' => 'https://www.myapp.com/post_login_page' );
$loginUrl = $facebook->getLoginUrl($params);

I ran into the same problem, but I was using the koala gem for Ruby on Rails.
After trying their OAuth Playground I found out how to make it work in Rails as well, it's as easy as:
oauth = Koala::Facebook::OAuth.new(app_id, app_secret, callback_url)
oauth_url = oauth.url_for_oauth_code << "&scope=user_friends"
Maybe this might help other Rails/Facebook API beginners.

Related

An empty array of likes even though correct permissions - Facebook App

I'm going slightly mad because of my problem. I prepared facebook app based on facebook-php-sdk. My app's permisions are:
publish_acions, user_location, user_likes, friends_likes
Everything goes correct with that code:
$facebook = new Facebook(array(
'appId' => '####',
'secret' => '####',
));
I can also receive
$user = $facebook->getUser();
$user_profile = $facebook->api('/me');
$userId = $user_profile['id'];
But I can't receive
$user_likes = $facebook->api('/me/likes/');
It just gives me an empty array (I'm quite sure I like the page). So what's the reason?
Thanks in advance...
First of all: Use The JavaScript for the login process, it´s much easier to handle and debug. Also, it´s better for the usability, because it does not redirect: https://developers.facebook.com/docs/reference/javascript/FB.login/v2.1
Use the "scope" parameter as it is mentioned in the docs and check if the required permissions are really asked for in the authorization popups.
Btw, the correct endpoint would be /me/likes (without the slash at the end), just another idea why it does not work.
And then there is the review process, most permissions (like user_likes) need to get approved by Facebook before they can be used for other users (except for users with a role in the App settings). Check out the changelog and the review guidelines for more information:
https://developers.facebook.com/docs/apps/changelog
https://developers.facebook.com/docs/apps/review/login
Friend permissions are deprecated btw, there is no "friends_likes" anymore.

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.

Facebook Permission not asked

I created an app in facebook and added read_mailbox to the required permissions.
When FB asks me to agree on granting access for the app, it only askes for my public profile and friendlist.
All the other stuff works pretty well and I receive a auth_token as well.
I'm using the PHP SDK.
You are most likely trying to set the permission in the app settings when you should be setting it in the scope while coding your application.
$params = array(
'scope' => 'read_mailbox',
'redirect_uri' => 'https://www.myapp.com/post_login_page'
);
$loginUrl = $facebook->getLoginUrl($params);
https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/

How do I check if a facebook account is currently logged in before requesting permission for my app? (using php sdk)

I'm using the php sdk v3.0.1.
I am trying to get offline access from users.
When my app requests permission from the user, it does so for the currently logged in user. I'd like to first check if a facebook account is logged in, and if so display a message. for example:
User "John Doe" is currently logged in.
then I'd have a link to "log out" or a link to continue to the permission page.
I was trying this but it always returns 0:
$facebook = new Facebook(array(
'appId' => 'XXX',
'secret' => 'YYYYYYYYY',
));
// Get User ID
$user = $facebook->getUser();
if($user)...
else...
the if statement always fails and then when the else is procesed and I send them to the login page, it requests permission for the currently logged in user (which I don't want).
I've searched extensively and can't find an answer. :-/ Any help or suggestions would be appreciated. I'm completely new to the facebook api.
Basically you would like authentication and permission requests to be separate. Correct me if I'm wrong about that. So you can just send users through a plain authentication step:
$loginUrl = $facebook->getLoginUrl();
and then later send them through again with the proper permissions.
$arg['req_perms'] = "[permissions here]";
$loginUrl = $facebook->getLoginUrl($arg);
This will get you a separate login and permission request step.

More settings for the facebook php API

Maybe I searched completely in the wrong way, and the facebook documentation pretty much sucks in my opinion.
I was wondering, I'm connecting to facebook with the settings below and that works (I'm able to retrieve the profile information of the logged in user allows my application to access his profile.) Are there other options I can set, like the callback url and the expiration (which I want to set to never, so I can save the token in my db and re-use it)?
This is the config now:
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxx',
'cookie' => true
));
I'm also connection to twitter and there I'm able to this:
$this->configTwitter = array(
'callbackUrl' => 'xxxxxxxxxxxx',
'siteUrl' => 'http://twitter.com/oauth',
'consumerKey' => 'xxxxxxxxxxxx',
'consumerSecret' => 'xxxxxxxxxxxx'
);
Thanks in advance!
Facebook should take a look at Twitter
After trying a few days, spitting the documentation of the Graph OAuth 2.0 (which doesn't work as good as expected and searching the internet I found a solution which I used to create the following script:
// Config
$this->redirectUrl = 'http://www.mywebsite.com/facebook'
$this->clientId = 'APPLICATION_ID';
$this->permissions = 'publish_stream,offline_access';
// Check if a sessions is present
if(!$_GET['session'])
{
// Authorize application
header('Location: http://www.facebook.com/connect/uiserver.php?app_id='.$this->clientId.'&next='.$this->redirectUrl.'&perms='.$this->permissions.'&return_session=1&session_version=3&fbconnect=0&canvas=1&legacy_return=1&method=permissions.request');
}
else
{
$token = json_decode($_GET['session']);
echo $token->access_token; // This is the access_token you'll need!
// Insert token in the database or whatever you want
}
This piece of code works great and performs the following actions:
Log in if the user isn't logged in to facebook
Asks if the user wants to add the application and grants the requested permissions (in my case: publish_stream and offline_access) in one dialog
returns to the page you specified under redirectUrl with an access_token (and because we requested for offline access this one doesn't expire)
I then store the token in the database so I won't have to request it again
Now you can, if you wish use the facebook code, or you're own code to get the users data, or other information from facebook (be sure you requested the right permissions)
Don't now if this is facebook-valid code, but it works great and I can easily define the 'config' like I wanted....
There are many settings you can set at the point of authenticating. Extended permissions let you set the offline_access so that you can authenticate and store your session in a db. More info on extended permissions are at developers.facebook.com/docs/authentication/permissions and you can read my blog post for more info on how to use them at http://www.joeyrivera.com/2010/facebook-graph-api-app-easy-w-php-sdk/