【问题标题】:Session.StatusCallback cannot be resolved to a type - Facebook APISession.StatusCallback 无法解析为类型 - Facebook API
【发布时间】:2013-06-04 19:40:42
【问题描述】:

我按照 Facebook 上的登录身份验证教程,并将以下代码复制到我的 android 应用程序中

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

但是,它给了我以下错误:

Session.StatusCallback cannot be resolved to a type

这会导致以下错误:

callback cannot be resolved to a variable

还有其他地方调用 Facebook API 时会出现错误,但并不是所有的 Facebook API 调用都如此。我收到错误的另一个地方如下:

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

在它不识别Request.GraphUserCallback的地方,然后执行Async()。我收到以下错误:

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

有人对如何解决这个问题有任何建议吗?

提前感谢您的帮助!!

【问题讨论】:

    标签: android eclipse facebook facebook-android-sdk facebook-authentication


    【解决方案1】:

    我遇到了和你第一个一样的问题,我通过删除解决了它

    import android.service.textservice.SpellCheckerService.Session;
    

    添加

    import com.facebook.Session;
    

    【讨论】:

    • 你是救生员!!你为什么认为 SpellCheckerService.Session 会造成问题,因为我遇到了完全相同的问题,并且通过删除语句得到了解决!
    【解决方案2】:

    我有一个类似的问题,问题是我在文件中有这两个导入

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

    那些请求和会话模块被覆盖

    com.facebook.Session
    com.facebook.Request
    

    实际上,我刚刚删除了两个 android 导入,一切都运行良好。它们似乎没有被使用,但是 eclipse 出于某种奇怪的原因将它们添加了进来。

    根据你的输出判断

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

    我会说听起来您在某处发生了相同的导入,并且它们正在覆盖 facebook 导入。

    【讨论】:

      【解决方案3】:

      从 Volley 框架导入 Request 和 Session 类时遇到此问题。尝试使用具有 Session 和 Request 包名称的类,它对我有用。请参阅下面的代码。

      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】:

        对于您的第一个问题,您使用哪个导入?我将它用于回调:

        import com.facebook.Session.StatusCallback;
        

        您使用的是哪个 Facebook SDK?最新的? 我使用的是最新的 sdk 4.01,但是这个 sdk 不支持这个包

        【讨论】:

        • 我正在使用 import com.facebook.SessionState;并且导入其他任何东西都会给我带来冲突。我认为我正在使用 Facebook SDK 3.0.1
        • 嗯,愚蠢的问题,但是,您是否将 facebook sdk 作为 android 项目导入,并将其作为库项目包含到项目的构建路径中?
        • 是的,我做到了。整个项目之前都在工作,然后我更新了我的 git repo 并且事情坏了,现在我正在尝试再次修复它。对 Facebook API 的其他调用不会引发错误。但是这些特殊的是,我不知道为什么。
        【解决方案5】:

        我收到一条消息:“无法解析符号会话”。因此,问题出在未插入的库“facebook”中。我就这样解决了。 1. 打开项目结构(文件 > 项目结构)。 2. 选择左侧窗格中的模块。 3. 选择您的项目名称。 4. 单击依赖项选项卡。 5. 点击底部的加号。选择“模块依赖”并单击“facebook”。 6. 按 OK,然后按 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);
              }
          }
          

          facebook sdk 的参考链接,您可以在其中下载和使用它。它为我工作 http://www.filedropper.com/facebooksdk

          【讨论】:

            【解决方案7】:

            只需删除 FB SDK 并重新下载即可。 您的 SDK 可能被其他推送到 git 的人损坏了。

            【讨论】:

              猜你喜欢
              • 2014-08-02
              • 2015-10-22
              • 1970-01-01
              • 2021-08-28
              • 2013-12-14
              • 2020-04-07
              • 2015-06-10
              • 2015-11-22
              • 1970-01-01
              相关资源
              最近更新 更多