I am using ParseFacebookUtils to login through facebook,with this code i successfully logged in through Facebook and got all data of user.
But if Facebook native application is installed on my phone facebook auth dialog is not called every time and went in User is null condition. See following code i used :
ParseFacebookUtils.logIn(Arrays.asList(Permissions.Friends.ACTIVITIES),
this, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if(user == null){
System.out.println(" Here");
}else if(user.isNew()){
}else{
}
But i want to open Facebook auth dialog every time that will return me any ParseUser.
How to achieve this kind of funcationality ?
Note :
I checked my Facebook KeyHash and Facebook AppID is correct.
I used Facebook sdk 3.0 and parse sdk 1.2.3
I dont know how to achieve this IN my application
Try this:
Session session = ParseFacebookUtils.getSession();
if (session != null)
session.closeAndClearTokenInformation();
ParseUser.logOut();
This will finish your Facebook session on curren machine. Next time when you ry login - F login dialog will appear.
Related
No matter what I try, Facebook GraphUser user is alsways null. I am trying the following using Facebook SDK 3.23.0
loginButton
.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
#Override
public void onUserInfoFetched(GraphUser user) {
FragmentFour.this.user = user;
if (user != null) {
Log.d("Name",user.getName());
} else {
Log.d("Name","Not Logged in!!");
}
}
});
I have done with hash key and have successfully experimented Facebook samples in Facebook SDK using own created app id. But whenever I try above code i always get user as null. Please help.
I solved it by myself by adding
loginBtn.setReadPermissions("user_friends");
loginBtn.setFragment(this);
I am using following code to logout from facebook..
public static void callFacebookLogout(Context context) {
Session session = Session.getActiveSession();
if (session != null) {
if (!session.isClosed()) {
//session.close();
session.closeAndClearTokenInformation();
}
} else {
session = new Session(context);
Session.setActiveSession(session);
//session.close();
session.closeAndClearTokenInformation();
}
}
After this, I am unable to fetch user details after logging in as I am getting null GraphUser in..
mFacebookLogin.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
#Override
public void onUserInfoFetched(GraphUser user) {
if (user != null) {
getFacebookUserInformation();
}else {
//handle error case
}
}
});
and I am getting callback in
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
Log.i("facebook", "isOpened: "+state.isOpened());
Log.i("facebook", "isClosed: "+state.isClosed());
}
};
with state as isClosed true.
So in a nutshell flow is like this..
open my android app
click on facebook login button
native facebook app will open and ask for user credentials.
enter user credentials
after Login native facebook app will ask for app permission to access public profile and email.
user authorize the app
call comes back to android app , first in onAcvitityResult(), then in onUserInfoFetched() after that in call(). In onUserInfoFetched GraphUser is not null and in call() state is opened.
Android app makes a separate request to get user details and show it on app UI.
Logout from android app and call facebooklogut() function. Close the android app.
Open the android app(its a new android app session)
go on screen where facebook login button is there.
Click on facebook login button.
facebook native app opens with progressdialog.
Since user is already signed in and already authorized the android app, call comes back to android app.
but this time onUserInfoFetched() has null GraphUser and call() method has closed state.
So I am unable to fetch user details
I'm trying to link an existing user to his or her Facebook account using Parse. After logging into through Parse, the user can go to the SettingsActivity and link their Facebook account.
I achieved this by calling ParseUser.logInInBackground and then verified it by checking if ParseUser.getCurrentUser() != null.
In my SettingsActivity, the user can press a 'Connect to Facebook' button, which is supposed to link the account to Facebook, but it's not working. When the user clicks the button, I executed this code below, as per the Parse Android documentation:
mUser = ParseUser.getCurrentUser();
public void onToggleFacebookConnectedClick(View v) {
if (!ParseFacebookUtils.isLinked(mUser)) {
ParseFacebookUtils.link(mUser, this, new SaveCallback() {
#Override
public void done(ParseException ex) {
if (ParseFacebookUtils.isLinked(mUser)) {
Log.d(Application.APPTAG, "Woohoo, user logged in with Facebook!");
}
}
});
} else if(ParseFacebookUtils.isLinked(mUser)) {
ParseFacebookUtils.unlinkInBackground(mUser, new SaveCallback(){
#Override
public void done(ParseException ex) {
if (ex == null) {
Log.d(Application.APPTAG, "The user is no longer associated with their Facebook account.");
}
}
});
}
}
I am getting the error: com.parse.ParseException:java.lang.IllegalArgumentException: Cannot save a ParseUser until it has been signed up. Call SignUp first.
The user has already signed up (not using Facebook), so I am confused as to why I'm am getting this message. How can I resolve this issue?
It turns out I made a silly mistake. I wasn't linking the user correctly because my Facebook Application ID was not set correctly in my Parse App Settings.
I ran into some strange behaviour while implementing the facebook login from Parse.com in my application. Here's how to replicate it with the Blank Facebook App sample code from their samples:
I want to create a new "Post" associated to the current user. At the end of the onCreate() from UserDetailsActivity, I added :
ParseObject post = new ParseObject("Post");
post.put("name", "New post");
post.put("user", ParseUser.getCurrentUser());
post.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
e.printStackTrace();
}
}
});
This work pretty well until I enable the localDataStore in the Application. The code above returns :
com.parse.ParseException : java.lang.IllegalArgumentException : Cannot save a ParseUser until it has been signed up. Call signUp first.
Note : the data associated with the ParseUser returned in the callback of ParseFacebookUtils.logIn() are null (objectId, username, ..) which explains the behaviour above.
The question is then : why adding
Parse.enableLocalDatastore(this);
to the App makes facebook login return an empty ParseUser ?
Ths error happens once every two launches :
First launch, no valid current user is stored in the offlineStore database, facebook login successfully add one, everything works perfectly
Second launch, a valid user is already stored, which is replaced by an "OfflineObject" User with no objectId or data, causing the error above.
I'm using Parse 1.5.0 & Facebook SDK 3.14.
It is very possible that ParseUser.getCurrentUser() is returning null as per https://parse.com/docs/android/api/com/parse/ParseUser.html#getCurrentUser(). You may want to do a facebook login first and then try to use the ParseUser
ParseFacebookUtils.logIn(getActivity(), new LogInCallback() {
#Override
public void done(ParseUser user, ParseException err) {
if(user != null) {
// use ParseUser here
}
}
});
Also, I wouldn't recommend using Parse 1.5.0 with version 3.14 of the facebook SDK. The docs for Parse https://www.parse.com/docs/android_guide#fbusers state that "Parse is compatible with v3.0 of the Facebook SDK for Android." My experience leads me to believe they aren't lying.
Trying to integrate facebook and twitter in android app.here i am using parse.com .facebook login is completed with doc provided by parse.com.but felt difficlt with twitter integration ,is there any SDk for twitter.suggest any tutorial (easily understandable example) using parse not regular twitter tutorials.thanks.
I think The tutorial in Parse it is the best tutorial about Twitter, What is your problem with Twitter?
0. Create the app in Twitter
1. Add compile 'com.parse:parsetwitterutils-android:1.10.+' to your Gradle dependiencies
2. Put this in your Activity ParseTwitterUtils.initialize("YOUR CONSUMER KEY", "YOUR CONSUMER SECRET");
3. add This to your Twitter login button
ParseTwitterUtils.logIn(this, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Twitter login.");
} else if (user.isNew()) {
Log.d("MyApp", "User signed up and logged in through Twitter!");
} else {
Log.d("MyApp", "User logged in through Twitter!");
}
}
});
Enable in Parse the Twitter authentication in Settings section and it is all.
I had problems with ParseFacebookUtils but Twitter is easier and no I didn't find a good example on net about Twitter + Parse.