我想实现获取用户数据的例子给出developers.facebook.com它工作正常,在模拟器和里显示的数据在logcat的,但是当我在实际设备尝试它,它不确实为登录这就是开屏为什么它直接写入消息的logcat “注销”(我想这意味着状态下关闭)以下是代码
私人无效onSessionStateChange(会话的会话,SessionState的状态,异常除外){
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
userInfoTextView.setVisibility(View.VISIBLE);
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
// Display the parsed user info
buildUserInfoDisplay(user);
Log.d(TAG,"Data Displayed");
}
}
}).executeAsync();
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
userInfoTextView.setVisibility(View.INVISIBLE);
}
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fblogin, container, false);
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("user_likes", "user_status","user_location","email","user_birthday"));
Log.d(TAG,"onCreateview");
userInfoTextView = (TextView) view.findViewById(R.id.userInfoTextView);
return view;
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
@Override
public void onResume() {
super.onResume();
// For scenarios where the main activity is launched and user
// session is not null, the session state change notification
// may not be triggered. Trigger it if it's open/closed.
Session session = Session.getActiveSession();
if (session != null &&
(session.isOpened() || session.isClosed()) ) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@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);
}
private void buildUserInfoDisplay(GraphUser user) {
/*if(user.getLocation()!=null){
userInfo.append(String.format("ID: %s\n\n",
user.getLocation()));
}*/
//Log.d(TAG+" Location",user.getLocation().toString());
Map<String, String> map;
map = new HashMap<String, String>();
try {
map.put("ID", user.getId().toString());
map.put("email", user.getProperty("email").toString());
map.put("rel status", user.getProperty("relationship_status")
.toString());
map.put("name", user.getName().toString());
// - requires user_birthday permission
map.put("birthday", user.getBirthday().toString());
map.put("gender", user.getProperty("gender").toString());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Log.d(TAG,"Info is: "+map);
}
}}
我已经安装在设备的Facebook应用程序,但它不会从应用程序启动的登录也。 我必须补充一点,以获得的WebView或登录屏幕登录不同。
请注意,这个代码在模拟器:感谢您的帮助