first, I'am sorry. i can't english well.
i have a problem in facebook sdk.
now i am developing login with facebook sdk.
and logout too.
but i can't find unlink api between my-app and facebook.
for example, some user using my app do not want to use my app more.
so he needs to ban me(or my app) in order to protect his data on facebook.
do you understand me? T.T please help me.
following flow is when the user unlinks the app himself directly.
but i want to do this in my app menu with login, logout, etc.
Menu Flow : (in facebook app settings) Apps -> Logged in with Facebook -> (choice a app) -> Remove App
FB.api("/me/permissions","DELETE",function(response){
console.log(response); //gives true on app delete success
});
You need a active access token of user to do this
Using Facebook sdk
new Request(
session,
"/me/permissions/{permission-to-revoke}",
null,
HttpMethod.DELETE,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
Related
I integrated Facebook login into my app, and It works fine. The issue is with the logout.
When I open the Facebook app on my device, I can perform a logout, so that the next time I open It, It will ask my If I want to login with my usual account, login with another account or even create a new account. Good, that is expected.
But this doesn't happen with my app. I mean, If the user opens my app, clicks in "logout" and the code below is ran
// Initialize Facebook SDK on the beginning.
FacebookSdk.sdkInitialize(this.getApplicationContext());
...
// Logout on user choice.
LoginManager.getInstance().logOut();
the next time he is back on the app and clicks to login he will be logged in directly with his account, he won't be asked with each account he wants to login.
I image that I need to clear all informations (tokens?) that are saved, which are being used into this directly login. Is this correct? If yes, how can I do it?
Thank you,
I am using this method. It's for SDK 4.6.0, but I guess it should be the same as 4.0. If not, just upgrade ;)
public void logoutFromFacebook(final LogoutFacebookListener listener) {
if (AccessToken.getCurrentAccessToken() == null) {
// already logged out
listener.onLoggedOutFromFacebook();
return;
}
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest
.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
LoginManager.getInstance().logOut();
listener.onLoggedOutFromFacebook();
}
}).executeAsync();
}
Listener:
public interface LogoutFromFacebookListener {
void onLoggedOutFromFacebook();
}
It seams like when you trying to login, facebook sdk uses your web browser (chrome, etc) in your case. And when you call LoginManager.getInstance().logOut(); you do logout just from facebook sdk, but you are still staying loggedin in your web browser. The Android and iOS SDKs don't currently support re-authentication. Hope they will be in future ;)
I implemented Facebook login button as described in https://developers.facebook.com/docs/facebook-login/android developer guide with profile and email read permissions.
When i press login button, Facebook app opens up and then I can log in and can get user data from Facebook. After this point, Facebook button turns to Log out button automatically. And when it is pressed, it logs out. So far, it works well.
Once Facebook log out done in my app side, and want to re-login with Facebook button, Facebook fails with key hash error. If I go to account settings in Facebook app, and remove my app from list then re-login returns success.
I also tried the solution here Android Facebook app logout issue but it didn't work either.
To clear, I use this code (found shared pref name in AccessTokenCache class):
SharedPreferences fbSharedPreferences = this.getSharedPreferences("com.facebook.AccessTokenManager.SharedPreferences", 0);
if (fbSharedPreferences != null) {
fbSharedPreferences.edit().clear().commit();
}
I'm using Facebook SDK 4.5. I'm testing with a real Facebook account. My app keys and hashes are set in Facebook app settings.
P.S. Question title is influenced from Facebook Login-Logout Issue Invalid Key Hash Error, While Trying to Login Again (which does not have a solution).
I was having the same issue, you need to delete app from facebook app and then logout. Following function will do the trick.
public void disconnectFromFacebook() {
if (AccessToken.getCurrentAccessToken() == null) {
return; // already logged out
}
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest
.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
LoginManager.getInstance().logOut();
}
}).executeAsync();
}
I am just new to Android Application and trying my hands on implementing Facebook login within my app. Successfully implementation of login but logout causes some trouble.
The first time I logged in it requested for my details and then signed in.
Next time I do the same it no more asks for my details, by default it logs me in with account.
What if I want to sign in with different user?
I have searched the net for solution and found out that -
- I cannot use Session as they were available only till Facebook SDK 3.X.X not for SDK 4.X.X
- I have tried calling LoginManager.getInstance().logOut();
(But I still have doubts where to use it.)
- I have also tried
new GraphRequest(AccessToken.getCurrentAccessToken(),"/me/permissions/", null, HttpMethod.DELETE,
new GraphRequest.Callback(){
#Override
public void onCompleted(GraphResponse graphResponse) {
LoginManager.getInstance().logOut();
}
}).executeAsync();
and I have also tried doing this :
` AccountManager am = AccountManager.get(context);
Account[] localAccounts = am.getAccounts();
for (int i=0; i<localAccounts.length; i++){
if (localAccounts[i].type.equals("com.facebook.auth.login")){
am.removeAccount(localAccounts[i], null, null);
}
}`
So it'll be really great if somebody could guide me properly on how to carry out a successful logout operation on Facebook, I'll be highly obliged.
Thanks in advance :)
The SDK will use either of two options to let the user log in to your app on Android:
using the native login dialog (which is powered by the Facebook app that is installed on the device)
using a webview-based dialog if the Facebook app is not installed on the device.
Both options depend on you being signed into Facebook in another app (your browser/your native Facebook app).
If you want to log into your app as a different user (there is really no need, because android system user profiles should be considered personal and individually owned), you need to go to the app you use for Facebook (native Facebook app/browser) and switch to a different profile there. After that you should be able to log into your app with that other profile.
Other than that, it is not your app's job to log people out of their Facebook.
Hello Friends
I am trying to get facebook album of a user . Problem is that it is returning albums for the user who is created the facebook app or who is the admin of that application .
For rest of the users it is returning the empty array
new Request(session, "/me/albums", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
System.out.println("Responce "
+ response.getGraphObject());
}
}).executeAsync();
This work for me because i have create a facebook app and for the rest of the users it is not returning the data. Please let me know how to resolve this.
Thanks
Amit
When your application is in sandbox/development mode you can not perform any api call for other user. To test your for other user, add the user as a tester, developer or admin. See details here
Since you probably ask for the user_photos permission already (else it would not work for the admin), there are two possible problems why it does not work for other users:
Your App is in not set public. Go to the "Status & Review" tab of your App settings and make sure that checkbox on top says "YES".
Most permissions (like user_photos) need to get reviewed by Facebook before you can use them for any other user: https://developers.facebook.com/docs/apps/review/login
[ SOLVED MYSELF. SEE THE ANSWER FOR SOLUTION. ]
I used android facebook sdk 3.5 in my application for login. Now when user logout from facebook in my application, i simply follwing below codes to logout.
session=new Session(context);
Session.setActiveSession(session);
session.closeAndClearTokenInformation();
Now, if user again try to login to facebook, I want to show login box as another user instead of doing login automatically from sessioncache.
[ remember that when your device has facebook application installed. Above problem only exist when device has facebook application else it is working fine. ]
I have googled this problem but not found the solution for SDK 3.5 . So how to force to show login box when user try to login again??
The only idea i got is we need to deauthorize our application on logout. So it will be asked to enter login again. Is this corret? if yes, then how can we deauthorize our app using sdk 3.5 ?
Finally i succeed in revoking authorization. here is the code.
Request deAuthorizeRequest=new Request(session, "/me/permissions", null, HttpMethod.DELETE, new Callback() {
#Override
public void onCompleted(Response response) {
((BaseFunctions) getActivity()).Log("unlink account : "+response.toString());
session.closeAndClearTokenInformation();
}
});
deAuthorizeRequest.executeAsync();
But it seems that this solved my problem partial. It is not showing login box dialog. Need to find solution for it. :)