2013-01-22 39 views
0

我第一次使用facebook SDK登录时,它的工作原理没有任何错误。但是当我尝试注销并再次登录时,出现了facebook错误。错误是"Facebook error: an active access token must be used to query information about the current user"getAccessToken()返回为空。任何答复和评论将不胜感激。facebook错误:必须使用活动的访问令牌来查询有关当前用户的信息

登录Activity.java

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
     if (APP_ID == null) { 
     Util.showAlert(this, "Warning", "Facebook Application ID must be specified before running"); 
    } 
    try { 
     PackageInfo info = getPackageManager().getPackageInfo("com.ff.fbin", PackageManager.GET_SIGNATURES); 
     for (Signature signature : info.signatures) { 
      MessageDigest md = MessageDigest.getInstance("SHA"); 
      md.update(signature.toByteArray()); 
      Log.e("TAG", "Reverse FB key: "+Base64Coder.encodeLines(md.digest())); 
     } 
    } catch (NameNotFoundException e) { 

    } catch (NoSuchAlgorithmException e) { 

    } 



    mLoginButton = (LoginButton) findViewById(R.id.login); 
    mFacebook = new Facebook(APP_ID); 
    mAsyncRunner = new AsyncFacebookRunner(mFacebook); 
    SessionStore.restore(mFacebook, this); 
    SessionEvents.addAuthListener(new SampleAuthListener()); 
    SessionEvents.addLogoutListener(new SampleLogoutListener()); 
    mLoginButton.init(this, mFacebook, mPermissions); 
} 


@Override 
protected void onActivityResult(int requestCode, int resultCode, 
           Intent data) { 
    mFacebook.authorizeCallback(requestCode, resultCode, data); 

    boolean isLogined = mFacebook.isSessionValid(); 
    Log.i(TAG, "getAccessToken, onActivity:" +mFacebook.getAccessToken()); 

    if (isLogined){ 
     mAsyncRunner.request("me", new SampleRequestListener()); 
    } 
} 

public class SampleRequestListener extends BaseRequestListener { 

    @Override 
    public void onComplete(final String response, final Object state) { 
     try { 
      Log.d(TAG, "Response2: " + response.toString()); 
      JSONObject json = Util.parseJson(response); 

      //Retrieve user information from facebook 

final Runnable mUpdateResultsSuccess = new Runnable() { 
    @Override 
    public void run() { 
     updateResultsInUiSuccess(); 
    } 
}; 

private void updateResultsInUiSuccess() { 
     if (loginSuccess){ 
      Log.i(TAG, "Login FB done"); 
      finish(); 
      Intent intent2 = new Intent(LoginScreen.this, MainMenu.class); 
      helper.insert_user(mFacebook.getAccessToken()); 
      intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity(intent2); 

     } else { 
      loading_text.setText("Error Processing"); 
      Log.i(TAG, "Login FB failed"); 
      try { 
       mFacebook.logout(this); 
      } catch (MalformedURLException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
       Log.e(TAG, "MalformedURLException: "+e.getMessage()); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
       Log.e(TAG, "IOException: "+e.getMessage()); 
      } 
      SessionStore.clear(this); 
      pDialog.dismiss(); 
      Toast.makeText(LoginScreen.this, "Login Failed. Please try again", Toast.LENGTH_LONG).show(); 
     } 
} 


public class SampleAuthListener implements com.ff.fbin.SessionEvents.AuthListener { 

    @Override 
    public void onAuthSucceed() { 
     Log.i(TAG, "You have logged in! "); 

     boolean isLogined = mFacebook.isSessionValid(); 
     Log.i(TAG, "isLogined: "+isLogined); 

     if(!isFinishing()){ 

     }; 

     if (isLogined){ 
      mAsyncRunner.request("me", new SampleRequestListener()); 
      pDialog.setMessage("Login in process......"); 
      pDialog.show(); 
     } 

    } 

    @Override 
    public void onAuthFail(String error) { 
     Log.i(TAG, "Login Failed: " + error); 
     Toast.makeText(getApplicationContext(), "Login Failed: " + error, Toast.LENGTH_LONG).show(); 
     pDialog.dismiss(); 
    } 
} 

public class SampleLogoutListener implements com.ff.fbin.SessionEvents.LogoutListener { 
    @Override 
    public void onLogoutBegin() { 
     Log.i(TAG, "Logging out..."); 
    } 

    @Override 
    public void onLogoutFinish() { 
     Log.i(TAG, "You have logged out! "); 
    } 
} 
+0

我得到同样的事情。我几天前没有收到这封信,之后也没有改变任何内容。 – Wenger

+0

嗯..你发布了关于这个问题的问题吗? –

回答

1

问题解决了,显然这个问题从这些sessionEvents来了。 SessionEvents.addAuthListener(new SampleAuthListener()); SessionEvents.addLogoutListener(new SampleLogoutListener());

我删除了上面的代码,并将SessionStore.restore移入了onResume,并且它没有错误地工作。上面的代码继续创建新的SampleAuthListener(),并使它堆叠在一起并多次执行相同的操作。这是我的项目导致facebook错误的原因。

相关问题