4

我遵循 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

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

提前谢谢你的帮助!!

4

7 回答 7

17

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

import android.service.textservice.SpellCheckerService.Session;

并添加

import com.facebook.Session;
于 2013-08-16T06:56:26.267 回答
3

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

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

那些 Request 和 Session 模块被覆盖

com.facebook.Session
com.facebook.Request

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

从你的输出来看

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

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

于 2013-08-02T05:45:33.217 回答
2

当已经从 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);
    }
};
于 2014-03-19T08:11:25.367 回答
1

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

import com.facebook.Session.StatusCallback;

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

于 2013-06-04T20:14:42.160 回答
0

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

于 2014-09-01T06:44:39.653 回答
0
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

于 2016-03-21T09:54:51.233 回答
-1

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

于 2013-06-04T21:23:32.620 回答