0

I am using parse for backend. I was trying to integrate my app with Facebook. I am following the tutorial given on parse.com. However, when I try to set up login using Facebook, I start having problems. In the tutorial, this small piece of code is given:

ParseFacebookUtils.logInWithReadPermissionsInBackground(this, permissions, new LogInCallback() {
 @Override
 public void done(ParseUser user, ParseException err) {
 if (user == null) {
   Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
 } else if (user.isNew()) {
   Log.d("MyApp", "User signed up and logged in through Facebook!");
 } else {
   Log.d("MyApp", "User logged in through Facebook!");
 }
 }
});

However,when I copied this code in my application, I get an error which says " cannot resolve symbol 'logInWithReadPermissionsInBackground'". When I opened ParseFacebookUtils class in Android studio, it does not have any method called "logInWithReadPermissionsInBackground", but on the website ParseFacebookUtils class does have it. Why am I not getting this method ? I am using ParseFacebookUtilsV4-1.9.1.jar, which is the latest one. Please help me.

Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
user2709885
  • 413
  • 2
  • 8
  • 16

5 Answers5

4

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 did all the steps all over again:

  • First, I went to this website and created a new application.
  • I downloaded the Facebook SDK, I did the steps 4 and 5 and I added my package name and the default class name
  • I added the key hashes:

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

  • In parse.com inside Settings and Authentication, I added in Facebook Application the APP ID that was created in Facebook.
  • According to this, I did all the steps until Using Login or Share (including this).
  • I went here and I added my development hash key.
  • In the Settings of the application that I created in Facebook, I checked that in the Key Hashes field, there were both Development and Release Keys.
  • I used the tutorial from the correct answer to make my application live.
  • I downloaded the latest SDK of Parse (1.9.1) from QuickStart because 1.8 it's not working.
  • I added the new .jar file of the SDK and the ParseFacebookUtilsV4-1.9.1 inside the libs folder of my project and syncronized the build.gradle file.
  • I added this line in 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)

Community
  • 1
  • 1
Marialena
  • 817
  • 8
  • 31
2

I ran into the same problem but my issue was supplying an invalid context for the first parameter for logInWithReadPermissionsInBackground. Since I am calling it from inside the OnClickListener class, the first parameter should be MyActivity.this rather than this. You might have the same case.

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final List<String> permissions = null;
            ParseFacebookUtils.logInWithReadPermissionsInBackground(SignInActivity.this, permissions, new LogInCallback() { ... }
schystz
  • 800
  • 1
  • 8
  • 21
0

"cannot resolve symbol" usually happen from missing dependencies in the gradle file of the app.

As ParseFacebookUtils.jar became a separate jar file, you need to add dependency for it directly, not only add dependency for Parse.jar as before.

Here is what I added.

compile fileTree(dir: 'libs', include:'ParseFacebookUtilsV4-*.jar')

Hope this solve your problem. Cheers.

0

If you copy the ParseFacebookUtilsv4-1.9.4.jar file to the libs folder of your project:enter image description here

and your dependecies look like this:

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   compile 'com.android.support:appcompat-v7:22.2.0'
   compile 'com.parse.bolts:bolts-android:1.+'
   compile 'com.facebook.android:facebook-android-sdk:4.1.0'
   compile fileTree(dir: 'libs', include: 'Parse-*.jar')
 }

I don't see any reason why logInWithReadPermissionsInBackground shouldn't be resolved.

Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
0

If you use the parse latest version then change to:

Parse-1.9.2.
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
Gopi Cg
  • 384
  • 3
  • 7