My code is.
private void facebook() {
List permissions = Arrays.asList(\"public_profile\", \"email\");
ParseFacebookUtils.logInWithRead
Have you added Facebook activity into your Manifest?
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
Not sure but check the Key Hash settings on https://developers.facebook.com for your app. You need to have both key hashes for release and debug version set in app developer console. It might be that you've just set the key hash for the debug environment. For more see Setting a Release Key Hash. Hope it helps.
ParseFacebookUtils.logInWithReadPermissionsInBackground(this, Arrays.asList("email", "user_photos", "public_profile", "user_friends")
, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
Toast.makeText(Form.this,"User Already logged up through Twitter!",Toast.LENGTH_LONG).show();
} else if (user.isNew()) {
} else {
Toast.makeText(Form.this,"User Already logged up through Facebook!",Toast.LENGTH_LONG).show();
}
}
});
Add this also..
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}
this code is working perfect..
Those are the steps I followed to do the signup / login / linking of users with ParseUsers according to Parse documentation and some tips I found on the web. Please check that you didn't miss any step because I had the same problems with you and I had to do all the steps all over again:
Development Key:
cd C:\Program Files\Java\jdk1.8.0_05\bin keytool -exportcert -alias androiddebugkey -keystore C:\Users\'YOUR NAME'.android\debug.keystore | C:\OpenSSL\bin\openssl sha1 -binary | C:\OpenSSL\bin\openssl base64
Release Key:
cd C:\Program Files\Java\jdk1.8.0_05\bin keytool -exportcert -alias 'NAME YOU GAVE AS ALIAS' -keystore | C:\OpenSSL\bin\openssl sha1 -binary | C:\OpenSSL\bin\openssl base64
libs folder of my project and syncronized the build.gradle file.strings.xml :<string name="facebook_app_id">1421******</string>I added this in my AndroidManifest.xml inside Application tag:
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
and this:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
In build.gradle of the app I added these inside the android because of some errors with Diamond (I am sorry I can't remember the exact error):
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
and I changed the SDK version to be numbers because of some error of undefined variables:
minSdkVersion 14
targetSdkVersion 19
The related dependencies inside the same file:
compile fileTree(include: 'Parse-*.jar', dir: 'libs')
compile fileTree(include: 'ParseFacebookUtilsV4-*.jar', dir: 'libs')
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
In the activity in which I want to do all those things with facebook I did the below things:
Parse.initialize(this, "hoMaK", "wWV193mE");
FacebookSdk.sdkInitialize(getApplicationContext());
ParseFacebookUtils.initialize(getApplicationContext());
final List<String> permissions = Arrays.asList("public_profile", "email");
fb.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
proDialog.show();
ParseFacebookUtils.logInWithReadPermissionsInBackground(HomeActivity.this, permissions, new LogInCallback() {
@Override
public void done(final ParseUser user, ParseException err) {
if (user == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
Toast.makeText(getApplicationContext(), "Log-out from Facebook and try again please!", Toast.LENGTH_SHORT).show();
ParseUser.logOut();
proDialog.hide();
}
else if (user.isNew()) {
Log.d("MyApp", "User signed up and logged in through Facebook!");
if (!ParseFacebookUtils.isLinked(user)) {
ParseFacebookUtils.linkWithReadPermissionsInBackground(user, HomeActivity.this, permissions, new SaveCallback() {
@Override
public void done(ParseException ex) {
if (ParseFacebookUtils.isLinked(user)) {
Log.d("MyApp", "Woohoo, user logged in with Facebook!");
proDialog.hide();
}
}
});
}
else{
Toast.makeText(getApplicationContext(), "You can change your personal data in Settings tab!", Toast.LENGTH_SHORT).show();
}
} else {
Log.d("MyApp", "User logged in through Facebook!");
if (!ParseFacebookUtils.isLinked(user)) {
ParseFacebookUtils.linkWithReadPermissionsInBackground(user, HomeActivity.this, permissions, new SaveCallback() {
@Override
public void done(ParseException ex) {
if (ParseFacebookUtils.isLinked(user)) {
Log.d("MyApp", "Woohoo, user logged in with Facebook!");
proDialog.hide();
}
}
});
}
else{
proDialog.hide();
}
}
}
});
}
});
With all the above steps, I can sign up or login using my Facebook account and I am getting a new line in _User object in Parse.com in which I can change the data any time I want to (I handle it as a normal sign-up user)
Don't forget to initialize your the ParseFacebookUtils class in your application class as it is presented in the docs:
ParseFacebookUtils.initialize(this);
Also pass on the onActivityResult to ParseFacebookUtils.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}
Hope that helps ;).
Source: https://parse.com/docs/android/api/com/parse/ParseFacebookUtils.html
Let's try:
In your build.gradle
remove this line compile fileTree(dir: 'libs', include: ['*.jar']),
then add these:
compile files('libs/Parse-1.9.1.jar')
compile files('libs/ParseFacebookUtilsV4-1.9.1.jar')
that works perfectly for me and with this case :D