I have a problem, logging out from Facebook with the FacebookSDK (3.7). I already tried lots of possibilities but none seems to work,
when I try with:
fb.logout(ScoreActivity.this);
or with
fb.logout(ScoreActivity.this.getApplicationContext());
or something similar, i get an IllegalArgumentException (but don't know why..)
just a short explanation: "fb" is an object of the type Facebook, and "ScoreActivity" is the activity, where the logout should happen.. Just form Information: The Login is working..
the other method I tried is the following:
I call the following function:
logoutfromfb(ScoreActivity.this.getApplicationContext());
which is defined like this:
public static void logoutfromfb(Context context) {
Session session = Session.getActiveSession();
if (session != null) {
if (!session.isClosed()) {
session.closeAndClearTokenInformation();
//clear your preferences if saved
}
} else {
session = new Session(context);
Session.setActiveSession(session);
session.closeAndClearTokenInformation();
//clear your preferences if saved
}
}
should actually work and I dont even get an error, looking in my LogCat but it's not working, I can press the button how often I want, but nothing happens....
I really hope somebody can help me...
If you need more Infos, just let me know.
I have the same problem it seems that the logout works but since you have the official facebook application still logged in it will authenticate silently again. I'm thinking about creating a "isLogged" var and store it so that when someone logout and restart the app it will not even verify if the user is logged bypassing facebook session verify.
fb.getSession().closeAndClearTokenInformation();
you can use this. it worked for me.
Related
I'm making login function. I want to add automatic login. So, I referenced the code below.
if (currentUser != null) {
Log.d(TAG,"");
/* Intent */
}else{
Log.d(TAG,"");
}
For testing, I deleted user from firebase authentication console. I expected the automatic login to fail, but it wasn't.
It seems that there is cache memory remaining. If I clear the cache memory, automatic login may not work.
So, I want to add function to know user has authentication to automatic login.
Any other method is fine. I'd appreciate it if you could tell me how to do it.
I am working on a Java project which has Evernote services integrated into it through an app created on Evernote. Currently, everything is working fine except for access-revocation.
When an user who has already authorized the app, at some point decides not to give this app any access, I would like to also de-authorize the app from the users evernote account.
For this, I am searching for some sample, but came empty handed. One link I found was this, where it was required to call that method with UserStore. I have the access-token, but unfortunately I am only working with NoteStoreClient, rather than UserStore.
Here is the revocation code I have so far.
Person person = this.personService.getCurrentlyAuthenticatedUser();
if (!(person == null)) {
if (person.isEvernoteConsumed()) {
try {
this.evernoteDAO.deleteEvernoteForUser(person.getId());
Evernote evernote = getUsersEvernote(person.getId());
EvernoteAuth evernoteAuth = new EvernoteAuth(EVERNOTE_SERVICE, evernote.getAccessToken());
NoteStoreClient noteStoreClient = new ClientFactory(evernoteAuth).createNoteStoreClient();
}catch (Exception e){
e.printStackTrace();
}
}
}
Nothing fancy in that code, I know. If anyone has any idea of revocation from Evernote, kindly let me know. Thank you.
You're on the right track, that UserStore method will let you revoke your OAuth session. Like you said, you have to use the userstore client instead, you should be able to create it the same way as you did the notestore client:
UserStoreClient userStoreClient =
new ClientFactory(evernoteAuth).createUserStoreClient();
userStoreClient.revokeLongSession(evernoteAuth);
Googling didn't help me. I'm trying to push data on Facebook dashboard via Facebook app events
My code is:
AppEventsLogger logger = AppEventsLogger.newLogger(this);
logger.activateApp(this, Utility.FACEBOOK_ID);
logger.logEvent(AppEventsConstants.EVENT_NAME_COMPLETED_TUTORIAL);
So, activateApp works fine, but logEvent doesn't.
I've checked app ID and recreated it, but I have the same problem.
Hi you can try add the next row after 'logEvent' method.
logger.flush();
I hope it will be helpful for you.
you need to make sure you have initialized the FB successfully before you calling the logger events:
Facebook.sdkInitilize(Context context);
I am implementing FB in one of my app.I am using jar 0.8.25. Its working fine on all simulators from 5 to 7.1.And for devices works only for OS 5 and 6 but not working on device 7 and 7.1.For OS 7 after log in success it remains on FB page it doesn't redirect back. and when i press back button, i get error encountered unable to refresh access token with try again button.
When analyzing on console it never finds access token single time for OS 7.while for 5 and 6 its working perfectly.
Please tell what may cause the issue.
Thanks,
This isn't a solution to your specific problem. I mentioned in the comments that I'm using an interface. So I'm posting here as its too much for the comment section. It is also not the COMPLETE solution, you will need to handle the flow and expired tokens, this is just to show you the logic of how I did this.
For my interface I open a browserfield to the Oauth url:
https://www.facebook.com/dialog/oauth?client_id=<APP_ID>&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html&scope=publish_actions
And I add a listener to this browser to listen for the redirects after login. Once you have the access token, you should persist it and close the browserfield.
private class OAuthScreen extends MainScreen
{
BrowserField browser_field;
LoadingDialog loading_dialog;
public OAuthScreen(final Command task)
{
super(VERTICAL_SCROLL | HORIZONTAL_SCROLL);
BrowserFieldConfig browserConfig = new BrowserFieldConfig();
browserConfig.setProperty(BrowserFieldConfig.VIEWPORT_WIDTH, new Integer(Display.getWidth()));
browser_field = new BrowserField(browserConfig);
browser_field.addListener(new BrowserFieldListener()
{
public void documentCreated(BrowserField browserField, ScriptEngine scriptEngine, Document document) throws Exception
{
int index = browserField.getDocumentUrl().indexOf("#access_token=");
if (index == -1)
{
super.documentCreated(browserField, scriptEngine, document);
}
else
{
access_token = browserField.getDocumentUrl().substring(index + "#access_token=".length(), browserField.getDocumentUrl().indexOf("&"));
PersistentObject store = PersistentStore.getPersistentObject(STORE_KEY);
FacebookTokens store_tokens = new FacebookTokens();
store_tokens.access_token = access_token;
store.setContents(store_tokens);
store.commit();
if (task != null) task.execute();
OAuthScreen.this.close();
}
}
public void documentLoaded(BrowserField browserField, Document document) throws Exception
{
super.documentLoaded(browserField, document);
loading_dialog.close();
}
});
// whatever loading dialog you want, this sometimes takes a while to open
loading_dialog = LoadingDialog.push(loading_field);
add(browser_field);
browser_field.requestContent("https://www.facebook.com/dialog/oauth?client_id="+APP_ID+"&response_type=token&redirect_uri=http://www.facebook.com/connect/login_success.html&scope=publish_actions");
}
}
The callback task is just for if I want to perform a call directly after login.
Now just perform API calls as you need them. API methods here https://developers.facebook.com/docs/graph-api/reference/v2.0/
Methods that require the access token, should have it appended to the url such as, https://graph.facebook.com/me/feed?access_token=" + access_token
Be aware that clearing your access token won't clear the token stored in the browser field. And will mean that you can't login next time (because the browser is still logged in).
So if you want to logout you need to open this link in a browserfield before clearing your local access token "https://www.facebook.com/logout.php?next=http://www.facebook.com/connect/login_success.html&access_token=" + access_token
Clearing the cookies of the browser should suffice, but I haven't found a way to do this.
I have my Google App Engine Java application humming along nicely using openid/federated login.
I save a UserProfile object that I persist once we have a logged in user that saves a reference to the UserService.getCurrentUser() object (and its userid) like so:
UserService userService = UserServiceFactory.getUserService();
user = userService.getCurrentUser();
userId = user.getUserId();
profile = UserProfileBin.getInstance().getByUserId(user.getUserId());
if (profile == null) {
profile = new UserProfile();
profile.setUser(user);
profile.setUserId(user.getUserId());
profile.setCreatedDate(new Date());
pm.makePersistent(profile);
id = profile.getId().getId();
}
...
Well, that is all working fantastically. I'm using the openId selector and am logging into the app using a bunch of different openid providers. There are no issues.
Now, I want to let people use their facebook logins, and I have that part going as well. I'm using the server side authentication flow. I'm able to complete the authorization and retrieve the access token, and I am using restFB. I can connect to the graph api and get whatever I need.
So my question is this: I don't know what the best way is to go about taking this information and letting my app know that somebody is logged in.
I assume Userservice.getCurrentUser() is a no go.
I see OauthService.getCurrentUser(). That would be awesome if that "knew" that I had a Facebook user logged in. Then my user checks would just be along the lines of:
User user = UserService.getCurrentUser()
if(user == null)
{
user = OAuthService.getCurrentUser();
}
and merrily on my way I would go.
However, I don't see a way to register my Facebook user with OAuthService or anything.
I'm sure this has been done before.
How should I go about it? Is there a cute way to do this, or am I stuck turning on sessions and making a custom user object for my Facebook user and sticking it in the session and running a filter?
You'll need to enable sessions and store the relevant info about the user's login in the session. You may be able to configure things so that session data isn't loaded for users who are logged in using OpenID. I'm not sure, though, because I'm not overly familiar with Java.