Currenly i am using facebook javascript version 2.0 to get friends. but it only returns friends which are using app and not all friends.
FB.api(
"/me/friends",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
I tried the graph api explorer it is still returning friends using app and not all friends.
Thanks
This is by design. Facebook changed this in the 2.0 version, it's a "privacy issue"
https://developers.facebook.com/docs/apps/changelog
Related
I'am developing android application with facebook login and laravel REST API server. After user login on mobile, app get token which is sent to my server. On server I want get facebook user details by token.
Facebook SDK for PHP provides methods for that:
$session = new FacebookSession('token');
$me = (new FacebookRequest($session, 'GET', '/me',))->execute()->getGraphObject(GraphUser::className());
Can Laravel Socialite obtain user facebook details based on that token? Or just use that Facebook SDK?
I submitted a pull request to the repo which was accepted to the 2.o branch. You should be able to call Socialte::driver('facebook')->userFromToken($token) now.
https://github.com/laravel/socialite/pull/126
Cheers.
You can also extend your Socialite Facebook Provider.
For example;
Create a class as SocialConnect in App/Library folder
namespace App\Library;
use Laravel\Socialite\Two\FacebookProvider;
class SocialConnect extends FacebookProvider {
public function userFromToken($access_token)
{
$user = $this->mapUserToObject($this->getUserByToken($access_token));
return $user->setToken($access_token);
}
}
Then add these lines in boot method on your App/Providers/AppServiceProvider.php
$socialite = $this->app->make('Laravel\Socialite\Contracts\Factory');
$socialite->extend(
'SocialConnect',
function ($app) use ($socialite) {
$config = $app['config']['services.facebook'];
return $socialite->buildProvider(SocialConnect::class, $config);
}
);
Ready for use!
Socialite::driver('SocialConnect')->userFromToken($accessToken)
You can also add new methods as you wish in your SocialConnect class.
There is a method getUserByToken implemented in the Facebook Service Provider, however it's protected and only used internally to get the user details.
So you're better off using the Facebook SDK.
I'm a Facebook app developer. I have developed some apps. Everything was working good.
I have not developed any apps for the past 6 months. Now I started to develop an app with existing code. It is not working like what I expected. I don't know why. I have checked the coding with old apps. Everything is fine.
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
} else {
loginUrl = "https://www.facebook.com/dialog/oauth/?client_id=" + appId + "&redirect_uri=https://apps.facebook.com/appname/&scope=email,user_activities,user_likes,publish_actions,read_stream,publish_stream";
top.location.href = loginUrl;
}
}, true);
I couldn't post on my facebook wall. Error ((#200) The user hasn't authorized the application to perform this action) is coming.
Please advice.
The authorization did not work. Use FB.login for authorization: https://developers.facebook.com/docs/reference/javascript/FB.login/v2.1
Important note: Call it on user interaction, and NOT in the (asynchronous) callback function of FB.getLoginStatus. You should not directly present the authorization screen/popup to the user right when he opens your App/Website anyway.
Also, publish_stream is deprecated, publish_actions is the only permission you need for posting.
Using this link facebook-phonegap-cordova-without-plugin I create an phonegap Facebook app. In that app application when I am login that application it working fine. It give me facebook friendlist, birthday, friend links and its allow to me to post on Facebook wall me and my friends Facebook wall. but when I logout and logging into another user then it allow me to login but its gives me that message The User hasn’t authorized the application to perform this action. And when I try to post some thing then it gives me that error This does not let testing post to Facebook your public profile is you name, profile and other public info
I am using
latest cordova build
In developer.facebook my application name is Testing
I am using API v1.0
following code is to share the post
function share() {
openFB.api({
method: 'POST',
path: '/me/feed',
params: {
message: 'Testing Facebook APIs',
},
success: function() {
alert('the item was posted on Facebook');
},
error: errorHandler});
}
Please remember its working fine for me but when I logging using another user then it gives me error.
Have you tried this while logging out the first user :
Revoke permissions :
openFB.revokePermissions(
function() {
},
errorHandler );
If it's working for you only then check if your app is in developer mode or not.
Go to your app facebook dashboard.
App review tab.
Check and turn on to make your app public.
Hope it helps with your question.
Is there any graph API available to logout a user from facebook? My application is able to succesfully retrieve user information and post on a user's wall. The problem is after authorization the facebook user is left in logged-in state and control goes back to my application. I want to logout the user after authprization is over and before the control comes back to my application. I want to use graph API and do it at the back end being implemented in Java.
Thanks.
Facebook PHP SDK uses a function like this:
public function getLogoutUrl($params=array()) {
return $this->getUrl(
'www',
'logout.php',
array_merge(array(
'next' => $this->getCurrentUrl(),
'access_token' => $this->getAccessToken(),
), $params)
);
}
Which creates a URL like:
https://www.facebook.com/logout.php?next={YOUR_ENCODED_URL}&access_token={YOUR_ACCESS_TOKEN}
I believe the encoded URL must be owned by the application to whom the access_token belong.
If you get that URL right, it'll work (just tried for one of my applications)
No, you cannot log-out a user programatically via Java. You should create a logout link or button on the page instead.
you can use below code for logout from app
$logoutUrl = $facebook->getLogoutUrl();
echo 'Logout';
replace above code in
try{
//above code
} catch {
//other code
}
I am working on a django website which also allows users to sign in using their Facebook account. The login works fine, however I am not able to logout using Internet Explorer. The code seems to work fine on Firefox and Chrome.
Heres the code
function logoutFBUser()
{
//logout user from website and Facebook and reload
alert ("called FB logout");
if (FB.getAuthResponse())
{
alert ("has auth response");
FB.logout(function(response)
{
window.location.href = '/accounts/logout?next=/';
});
alert ("logged out of FB and redirected");
}
else
{
alert(" no auth response");
window.location.href = '/accounts/logout?next=/';
}
}
In Firefox, I get the alert of has auth response, however in IE, I get the alert no auth response. If I only use FB.logout without FB.getAuthResponse then the function hangs when it hits FB.logout.
What am I missing?
Finally solved this. I debugged into the javascript for FB.logout and for some reason it doesnt have the access_token which is why the call to FB.logout fails. Researching the Facebook documentation led me to this URL which I used for the logout process on my website successfully
Logoutlink from Facebook Documentation
https://www.facebook.com/logout.php?next=REDIRECT_URI&access_token=LOGGEDINUSER_ACCESS_TOKEN
Needless to say, I am using this on the serverside, so no need to use javascript any more.
Please refer Facebook Authentication documentation for more information.
http://developers.facebook.com/docs/authentication/
Thanks for all the help