Session.StatusCallback cannot be allowed for type - Facebook API

I followed the tutorial on Facebook authentication and copied the following code into my Android app.

private Session.StatusCallback callback = new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; 

However, it gives me the following errors:

 Session.StatusCallback cannot be resolved to a type 

This leads to the following errors:

 callback cannot be resolved to a variable 

There are also other places where Facebook API calls are called that give me errors, but this is not in all Facebook API calls. Another place where I get the error message is the following:

 Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { // If the response is successful if (session == Session.getActiveSession()) { if (user != null) { // Set the id for the ProfilePictureView // view that in turn displays the profile picture. Log.d("MainActivity", "onComplete() User logged in"); parent.owner = MainKickback.userConnection.add(new User(user.getId())); EventFragment e = (EventFragment) fragments[UPCOMING_EVENTS]; e.populateEvents(); } } if (response.getError() != null) { // Handle errors, will do so later. } } }); request.executeAsync(); 

where it does not recognize Request.GraphUserCallback and then executeAsync (). I get the following errors:

 Request.GraphUserCallback cannot be resolved to a type The method executeAsync() is undefined for the type DownloadManager.Request 

Does anyone have any tips on how to fix this?

Thank you for your help!

+4
source share
7 answers

I had the same problem as your first one, and I solved it by deleting

 import android.service.textservice.SpellCheckerService.Session; 

and adding

 import com.facebook.Session; 
+17
source

I had a similar problem and the problem was that I had these two imports in a file

 import android.app.DownloadManager.Request; import android.service.textservice.SpellCheckerService.Session; 

And these request and session modules redefined

 com.facebook.Session com.facebook.Request 

I actually just deleted two android imports and everything worked beautifully. They didn't seem to be used, but the eclipse added them for some strange reason.

Judging by your result

 The method executeAsync() is undefined for the type DownloadManager.Request 

I would say that it looks like you have the same import that happens somewhere and they override facebook import.

+3
source

This problem arose when request and session classes were already imported from the Volley structure. Try using a class with the package name for the session and request, this worked for me. See below code.

 private com.facebook.Session.StatusCallback callback = new com.facebook.Session.StatusCallback() { @Override public void call(com.facebook.Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; 
+2
source

For your first problem, what kind of import do you use? I use this for callback:

 import com.facebook.Session.StatusCallback; 

Which Facebook SDK are you using? The newest? I am using the latest sdk 4.01, but this sdk does not support this pakage

+1
source

I got a message: "Failed to resolve character session." So the problem was the facebook library not connected. I decided it like that. 1. Open the project structure (File> Project Structure). 2. Select "Modules" in the left pane. 3. Select a project name. 4. Click the "Dependencies" tab. 5. Click the plus sign below. Select Module Dependency and click facebook. 6. Click OK, then OK.

0
source
 package com.vishal.example; import com.facebook.Response; import com.facebook.UiLifecycleHelper; import com.facebook.Response; import com.facebook.UiLifecycleHelper; import com.facebook.Session; import com.facebook.SessionState; import com.facebook.model.GraphUser; import com.facebook.Request; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.TextView; public class MainActivity extends Activity { private UiLifecycleHelper uiHelper; private View otherView; private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set View that should be visible after log-in invisible initially otherView = (View) findViewById(R.id.other_views); otherView.setVisibility(View.GONE); // To maintain FB Login session uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); } // Called when session changes private Session.StatusCallback callback = new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; // When session is changed, this method is called from callback method private void onSessionStateChange(Session session, SessionState state, Exception exception) { final TextView name = (TextView) findViewById(R.id.name); final TextView gender = (TextView) findViewById(R.id.gender); final TextView location = (TextView) findViewById(R.id.location); // When Session is successfully opened (User logged-in) if (state.isOpened()) { Log.i(TAG, "Logged in..."); // make request to the /me API to get Graph user Request.newMeRequest(session, new Request.GraphUserCallback() { // callback after Graph API response with user @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { // Set view visibility to true otherView.setVisibility(View.VISIBLE); // Set User name name.setText("Hello " + user.getName()); // Set Gender gender.setText("Your Gender: " + user.getProperty("gender").toString()); location.setText("Your Current Location: " + user.getLocation().getProperty("name").toString()); } } }).executeAsync(); } else if(state.isClosed()) { Log.i(TAG, "Logged out..."); otherView.setVisibility(View.GONE); } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data); Log.i(TAG, "OnActivityResult..."); } @Override public void onResume() { super.onResume(); uiHelper.onResume(); } @Override public void onPause() { super.onPause(); uiHelper.onPause(); } @Override public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); } } 

Link to the link for facebook sdk, where you can download and use it. his work for me http://www.filedropper.com/facebooksdk

0
source

Just remove the FB SDK and reboot it. Your SDK is probably corrupted by others who clicked on git.

-1
source

Source: https://habr.com/ru/post/1484492/


All Articles