我在
https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/跟随“使用Facebook登录创建新的Android项目”部分的步骤登录过程很好.因为我想使用本机Android按钮供用户登录,所以我将以下代码移动到原生Android按钮的View.OnClickListener()中稍微修改代码.以下是侦听器中的代码:
Session.openActiveSession(MainActivity.this,true,new Session.StatusCallback() { // callback when session changes state @Override public void call(Session session,SessionState state,Exception exception) { if (session.isOpened()) { // make request to the /me API Request.executeMeRequestAsync(session,new Request.GraphUserCallback() { // callback after Graph API // response with user object @Override public void onCompleted(GraphUser user,Response response) { if (user != null) { Toast.makeText(getApplicationContext(),"Hello " + user.getName() +" "+user.getId()+"!",Toast.LENGTH_LONG).show(); } } }); } } });
onActivityResult()和AndroidManifest.xml与教程相同
@Override public void onActivityResult(int requestCode,int resultCode,Intent data) { super.onActivityResult(requestCode,resultCode,data); Session.getActiveSession().onActivityResult(this,requestCode,data); }
但是,我想在用户成功登录时请求“read_friendlists”.我在https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/阅读了教程,但它使用了Facebook SDK自定义按钮.如何使用上面显示的代码之类的原生Android按钮实现相同的行为?