public class FacebookInfo extends Activity {
...
String get_id, get_name, get_gender, get_email, get_birthday, get_locale, get_location;
private Session.StatusCallback fbStatusCallback = new Session.StatusCallback() {
public void call(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
public void onCompleted(GraphUser user, Response response) {
if (response != null) {
// do something with <response> now
try{
get_id = user.getId();
get_name = user.getName();
get_gender = (String) user.getProperty("gender");
get_email = (String) user.getProperty("email");
get_birthday = user.getBirthday();
get_locale = (String) user.getProperty("locale");
get_location = user.getLocation().toString();
Log.d(LOG_TAG, user.getId() + "; " +
user.getName() + "; " +
(String) user.getProperty("gender") + "; " +
(String) user.getProperty("email") + "; " +
user.getBirthday()+ "; " +
(String) user.getProperty("locale") + "; " +
user.getLocation());
} catch(Exception e) {
e.printStackTrace();
Log.d(LOG_TAG, "Exception e");
}
}
}
});
}
}
};
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fbinfo);
try {
openActiveSession(this, true, fbStatusCallback, Arrays.asList(
new String[] { "email", "user_location", "user_birthday",
"user_likes", "publish_actions" }), savedInstanceState);
}
catch (Exception e) {
e.printStackTrace();
}
private Session openActiveSession(Activity activity, boolean allowLoginUI,
StatusCallback callback, List<String> permissions, Bundle savedInstanceState) {
OpenRequest openRequest = new OpenRequest(activity).
setPermissions(permissions).setLoginBehavior(SessionLoginBehavior.
SSO_WITH_FALLBACK).setCallback(callback).
setDefaultAudience(SessionDefaultAudience.FRIENDS);
Session session = Session.getActiveSession();
Log.d(LOG_TAG, "" + session);
if (session == null) {
Log.d(LOG_TAG, "" + savedInstanceState);
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, fbStatusCallback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED) || allowLoginUI) {
session.openForRead(openRequest);
return session;
}
}
return null;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}
Trang Chủ
Android
PHP
Chuỗi
Dialog
Clipboard
Spinner
Auto Layout
ActionBar
Intent
Random
SQL
Admod
Version
TextView
Tabhost
Json
ListView
Time Picker
Calendar
Ham
FloatingActionMenu
Button
EditText
Activity
Custom Adapter
Xoay Màn Hình
Wifi & 3G
Lỗi
Fragment
Shape
SMS
Push
FireBase
CheckBox
Mảng
Facebook
Timer
Service
Text To Speech
Recycler View
Search This Blog
Wednesday, June 22, 2016
Login facebook - Lấy thông tin người dùng
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment