试试这个 Facebook Graph API:
private void faceBookLigin() {
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "user_photos", "email", "user_birthday", "user_friends", "user_location"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
accessToken = loginResult.getAccessToken();
/* make the API call */
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if (object == null) {
cUtils.Toast("Please try again!", getApplicationContext());
} else {
try {
String str_datestr = object.getString("birthday");
String strd = str_datestr.replaceAll("\\\\/", "/");
String str_date = strd.replaceAll("/", "-");
DateFormat formatter = new SimpleDateFormat("MM-dd-yyyy", Locale.getDefault());
Date date = null;
try {
date = formatter.parse(str_date);
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long output = 0;
if (date != null) {
output = date.getTime() / 1000L;
}
String str = Long.toString(output);
actualTime = Long.parseLong(str);
// Log.v("actualTime = ", " " + actualTime);
// Log.v("Email = ", " " + object);
email = object.getString("email");
facebook_id = object.getString("id");
first_name = object.getString("first_name");
last_name = object.getString("last_name");
user_location = object.getJSONObject("location");
gender = object.getString("gender");
verified = object.getBoolean("verified");
id = object.getString("id");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,first_name,last_name,email,gender,verified,age_range,hometown, birthday,location");
request.setParameters(parameters);
request.executeAsync();
if (accessToken != null)
LoginManager.getInstance().logOut();
}
@Override
public void onCancel() {
// App code
// Log.e(TAG, "facebook login canceled");
utils.cToast("facebook login canceled", getApplicationContext());
}
@Override
public void onError(FacebookException exception) {
// App code
// Log.e(TAG, "facebook login failed error" + exception);
utils.cToast("facebook login failed", getApplicationContext());
}
});
}