2

正如之前为片段使用的 Facebook 登录名一样,它工作得很好,所以现在随着需求的变化而改变了 facebook 登录活动,所以,我们有正常的 android 按钮,单击该登录对话框将出现用于用户交互以提供用户名和密码和当登录成功时,使用 executeme 请求获取用户详细信息。每个代码都已完成,但单击按钮对话框时未出现但 onsessionstate 更改日志显示输出为

首先显示 OPENING 比显示 LOGIN FAILED CLOSED

在 facebook 应用程序开发站点中提到的登录 facebook 所需的所有步骤都已执行,并且所有需要的类和元数据信息也在 andriod 清单文件中给出。

这里是登录的活动类

public class ResgistrationApp extends Activity {

    EditText username,password,name,nickname,email,phone;

    Button Registertauky,fb_connect;

    com.facebook.Session fbSession;
    ImageView user_image;
    private UiLifecycleHelper uihelper;

    private Session.StatusCallback sessioncallback=new Session.StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
            // TODO Auto-generated method stub
            Log.e("Sessionstate", ""+state);
            if(session.getState()==SessionState.OPENED)
            {
                makeuserdetailsrequest(session);
            }

        }
    };

    private Request.GraphUserCallback graphcallback=new Request.GraphUserCallback() {

        @Override
        public void onCompleted(GraphUser user, Response response) {
            // TODO Auto-generated method stub
            Log.e("FB RES", ""+response);
            Log.e("UID", ""+user.getId());
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) 

    {
        super.onCreate(savedInstanceState);
        //Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
        setContentView(R.layout.activity_resgistration_app);

        try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "com.primus.taukyresigstration", 
                    PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                }
        } catch (NameNotFoundException e) {

        } catch (NoSuchAlgorithmException e) {

        }

        uihelper=new UiLifecycleHelper(this, sessioncallback);
        uihelper.onCreate(savedInstanceState);

        username=(EditText) findViewById(R.id.register_usernameone);

        password=(EditText) findViewById(R.id.register_password);

        name=(EditText) findViewById(R.id.register_username);

        nickname=(EditText) findViewById(R.id.register_nickname);

        email=(EditText) findViewById(R.id.register_email);

        phone=(EditText) findViewById(R.id.register_phone);

        Registertauky=(Button) findViewById(R.id.Registertauky);

        user_image=(ImageView) findViewById(R.id.register_user_picture);

        fb_connect=(Button) findViewById(R.id.facbook_getinfo);

        fbSession=new Session(this);
        fbSession.addCallback(sessioncallback);


        //This going to register the tauky server

        Registertauky.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });


        //This button click going to connect to the facebook
        fb_connect.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub      
            if(fbSession.isOpened())
            {
                fbSession=Session.getActiveSession();
                //do the fetching of user details..
            }
            else
            {
                fbSession=Session.openActiveSession(ResgistrationApp.this, true, sessioncallback);
            }   
            }
        });
    }

    //--------------------------------------------------------------------------------------------------------------//



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        uihelper.onActivityResult(requestCode, resultCode, data);
        //Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
    }



    class LoginretrieveTask extends AsyncTask<Void, Void, Void>
    {
        Session session;

        public LoginretrieveTask(Session fbsession) {
            // TODO Auto-generated constructor stub
            session=fbsession;
        }

        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub

            return null;
        }

    }

    protected void makeuserdetailsrequest(Session session) {
        // TODO Auto-generated method stub

        Request user_request=Request.newMeRequest(session, graphcallback);
        user_request.executeAsync();
    }


    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        uihelper.onResume();

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        uihelper.onPause();

    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        uihelper.onDestroy();
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onRestoreInstanceState(savedInstanceState);
        uihelper.onSaveInstanceState(savedInstanceState);
    }
}

Log.e("会话状态", ""+状态); 这里显示 LOGIN FAILED CLOSED。

和清单文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.primus.taukyresigstration"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.primus.taukyresigstration.ResgistrationApp"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.facebook.LoginActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:label="@string/app_name">
        </activity>
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/appid"/>
    </application>

</manifest>

所以我可以指出我做错了什么。谢谢任何回复

4

1 回答 1

0

在这里您可以找到从活动登录的解决方案。

Facebook sdk 3.0.1 无法正常工作

这也可能对你有帮助......

Android 应用程序中的 Facebook 集成

于 2013-07-16T05:54:23.203 回答