Session.StatusCallback cannot be resolved to a type - Facebook API

与世无争的帅哥 提交于 2019-12-14 03:46:41

问题


I followed the login authentication tutorial on Facebook and have copied the following code into my android application

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

However, it is giving me the following errors:

Session.StatusCallback cannot be resolved to a type

Which is leading to the following errors:

callback cannot be resolved to a variable

There's also other places where Facebook API calls are made that are giving me errors, but it's not in all the Facebook API calls. Another place I'm getting an error 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 advice as to how to fix this?

Thank you for your help in advance!!


回答1:


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

import android.service.textservice.SpellCheckerService.Session;

and adding

import com.facebook.Session;



回答2:


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

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

And those Request and Session modules were overriding

com.facebook.Session
com.facebook.Request

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

Judging by your output

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

I'd say it sounds like you have the same imports happening somewhere and they're overriding the facebook imports.




回答3:


Got this issue when having both Request and Session classes from Volley framework already imported. Try using the class with the package name for Session and Request, it worked for me. See below's 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);
    }
};



回答4:


For your first problem, which import do you use ? I use this for the Callback:

import com.facebook.Session.StatusCallback;

Which Facebook SDK are you using ? The newest one ? I am using latest sdk 4.01 butin this sdk is not support this pakage




回答5:


I had a message: "Cannot resolve symbol Session". So, the problem was in non-plugged library "facebook". I resolved it so. 1. Open Project Structure (File > Project Structure). 2. Select Modules on the left pane. 3. Choose your project name. 4. Click Dependencies tab. 5. Click on the plus sign in the bottom. Select "Module dependency" and click "facebook". 6. Press OK, then OK.




回答6:


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);
    }
}

Reference link for facebook sdk where You can download and use it. its work for me http://www.filedropper.com/facebooksdk




回答7:


Just delete the FB SDK and re-download it. Your SDK is probably corrupted by others who pushed to git.



来源:https://stackoverflow.com/questions/16926123/session-statuscallback-cannot-be-resolved-to-a-type-facebook-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!