2013-01-31 2 views
0

facebook android sdk 인증 오류에 대해 물어 봅니다.facebook android sdk 인증 오류

프로그램을 실행할 때 "예기치 않게 중지되었습니다. 다시 시도하십시오."라는 오류가 나타납니다.

불만 오류는 NullPointerException 문제입니다. (facebook-android-sdk/facebook/src/com/facebook/internal/Validate.java)

이 문제를 어떻게 해결할 수 있습니까? 감사.

package com.example.fbloginau; 

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentActivity; 


public class MainFragment extends FragmentActivity 
{ 

private Fragment Fragment; 

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 

    if (savedInstanceState == null) { 
     // Add the fragment on initial activity setup 
     Fragment = new Fragment(); 
     getSupportFragmentManager() 
     .beginTransaction() 
     .add(android.R.id.content, Fragment) 
     .commit(); 
    } 
    else 
    { 
     // Or set the fragment from restored state info 
     Fragment = (Fragment) getSupportFragmentManager() 
     .findFragmentById(android.R.id.content); 
    } 
} 
} 

인용구

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<com.facebook.widget.LoginButton 
    android:id="@+id/authButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="30dp" 
    /> 

인용구

enter code here 

답변

0

당신은 어떤 웹 서비스를 통해 액세스 토큰을 획득하고 초기화를 시도 할 수 있습니다. 활동 내에서 세션을 승인하고 바인더를 통해 전달할 수 있습니다. Facebook facebook

여기의 예.

public class ClientService extends Service { 

    //Facebook object to operate from service 
    private Facebook facebook; 

... 

    private final ClientBinder clientBinter = new ClientBinder(); 

    /** Binder to service */ 
    public class ClientBinder extends Binder { 

     public ClientService getService() { 
      return ClientService.this; 
     } 
    } 

    @Override 
    public IBinder onBind(Intent intent) { 
     return clientBinter; 
    } 

    public void setFacebook(Facebook f) { 
     ClientService.this.facebook = f; 
    } 

    public boolean loggedFacebook() { 
     if (facebook == null) 
      return false; 
     return facebook.isSessionValid(); 
    } 

} 




public class DemoActivity extends Activity{ 

     private ClientService clientService; 
     private ServiceConnection clientConnection = new ServiceConnection() { 

      public void onServiceDisconnected(ComponentName name) { 
       mBound = false; 
      } 

      public void onServiceConnected(ComponentName name, IBinder service) { 
       ClientService.ClientBinder binder = (ClientService.ClientBinder) service; 
       clientService = binder.getService(); 
       mBound = true; 
       if (facebook != null) 
        if (facebook.isSessionValid()) 
         clientService.setFacebook(facebook); 
      } 
     }; 

    @Override 
    protected void onStart() { 
     super.onStart(); 
     Intent intent = new Intent(this, ClientService.class); 
     bindService(intent, clientConnection, Context.BIND_AUTO_CREATE); 
    } 

    @Override 
    protected void onStop() { 
     super.onStop(); 
     if (mBound) { 
      unbindService(clientConnection); 
      mBound = false; 
     } 

    } 




     private void logINFacebook() { 
       if (facebook.isSessionValid()) 
        return; 

       facebook.authorize(this, 
         getResources().getStringArray(R.array.facebookPermissions), 
         new DialogListener() { 
          public void onFacebookError(FacebookError e) {...} 

          public void onError(DialogError e) {...} 

          public void onComplete(Bundle values) { 
           if (mBound) { 
            clientService.setFacebook(facebook); 
           } 

           //Save to shared preferences(optional) 
           SharedPreferences.Editor editor = prefs.edit(); 
           editor.putString(FACEBOOK_TOKEN_PREFNAME, 
             facebook.getAccessToken()); 
           editor.putLong(FACEBOOK_EXPIRES_PREFNAME, 
             facebook.getAccessExpires()); 
           editor.commit(); 
          } 

     @Override 
     public void onActivityResult(int requestCode, int resultCode, Intent data) { 
      facebook.authorizeCallback(requestCode, resultCode, data); 
      super.onActivityResult(requestCode, resultCode, data); 
     } 

     }