I am using ParseFacebook SDK for my android application. I have used parse sdk code from there website, some of the code snippets are given below, it is successfully login with facebook, but i can't be able to extract my facebook information like: MyProfileImage, Username etc.
In Application Class:
ParseFacebookUtils.initialize(this);
In my class where i am using Facebook Login:
ParseFacebookUtils.logInWithReadPermissionsInBackground(SignInActivity.this, Arrays.asList("email", "user_photos", "public_profile", "user_friends"), new LogInCallback() {
#Override
public void done(ParseUser user, com.parse.ParseException e) {
if (user == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew()) {
}
);
Please help me out here to extract the information for username and profile image. Thanks in adavance
This is what works for me
public static void FaceBookLogin(final Activity context){
ArrayList permissions=new ArrayList<String>();
//permissions.add("publish_stream");
permissions.add("user_likes");
permissions.add("email");
permissions.add("user_birthday");
ParseFacebookUtils.logInWithReadPermissionsInBackground(context, permissions, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
Toast.makeText(context,"You have cancelled to connect via facebook",Toast.LENGTH_SHORT);
Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew()) {
Toast.makeText(context,"You have successfully connected via facebook",Toast.LENGTH_SHORT);
Log.d("MyApp", "User signed up and logged in through Facebook!");
try {
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject json, GraphResponse response) {
// Application code
if (response.getError() != null) {
System.out.println("ERROR");
} else {
System.out.println("Success");
String jsonresult = String.valueOf(json);
System.out.println("JSON Result" + jsonresult);
String fbUserId = json.optString("id");
String fbUserFirstName = json.optString("name");
String fbUserEmail = json.optString("email");
String fbUserProfilePics = "http://graph.facebook.com/" + fbUserId + "/picture?type=large";
ParseUser.getCurrentUser().setEmail(fbUserEmail);
ParseUser.getCurrentUser().put("First_Name",fbUserFirstName);
ParseUser.getCurrentUser().put("FaceBookUrl",fbUserProfilePics);
ParseUser.getCurrentUser().saveInBackground();
}
Log.v("FaceBook Response :", response.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context,e.getMessage(),Toast.LENGTH_SHORT);
}
if (ParseUser.getCurrentUser().getBoolean("IsTermsAccepted")==true){
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
}else{
Utils.ShowTermsofUse(context);
}
} else {
Toast.makeText(context,"You have successfully connected via facebook",Toast.LENGTH_SHORT);
Log.d("MyApp", "User logged in through Facebook!");
try {
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject json, GraphResponse response) {
// Application code
if (response.getError() != null) {
System.out.println("ERROR");
} else {
System.out.println("Success");
String jsonresult = String.valueOf(json);
System.out.println("JSON Result" + jsonresult);
String fbUserId = json.optString("id");
String fbUserFirstName = json.optString("name");
String fbUserEmail = json.optString("email");
String fbUserProfilePics = "http://graph.facebook.com/" + fbUserId + "/picture?type=large";
ParseUser.getCurrentUser().setEmail(fbUserEmail);
ParseUser.getCurrentUser().put("First_Name",fbUserFirstName);
ParseUser.getCurrentUser().put("FaceBookUrl",fbUserProfilePics);
ParseUser.getCurrentUser().saveInBackground();
}
Log.v("FaceBook Response :", response.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context,e.getMessage(),Toast.LENGTH_SHORT);
}
if (ParseUser.getCurrentUser().getBoolean("IsTermsAccepted")==true){
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
}else{
Utils.ShowTermsofUse(context);
}
}
Toast.makeText(context,err.getMessage(),Toast.LENGTH_SHORT);
}
}) ;
}
And dont forget to call onActivityResult:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
case FACEBOOK:
ParseFacebookUtils.onActivityResult(FACEBOOK, resultCode, data);
break;
}
Hope this helps
Related
Well, I want the details to be passed when moving to a next activity. Details like name, email, profile pic, gender.
This does not happen somehow when the user is logged in. However, the details are sent when I am logging in for the first time.
So I have two questions:
1) Why are the details not shown when the user is already logged in? Is there something that needs to be changed in the code?
2) Sometimes when I open the app after a long time it does not move to the DetailsActivity and opens the MainActivity with LoginButton with the text logout(so obviously it is still logged in yet returns null).
Have a look at my code:
AccessTokenTracker accessTokenTracker;
AccessToken accessToken = AccessToken.getCurrentAccessToken();
onCreate
callbackManager = CallbackManager.Factory.create();
loginButton.setReadPermissions(Arrays.asList("email, public_profile"));
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email, public_profile"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
getUserDetails(loginResult);
}
#Override
public void onCancel() {
//cancelled
}
#Override
public void onError(FacebookException exception) {
//handle error
}
});
accessTokenTracker = new AccessTokenTracker() {
#Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
accessToken = currentAccessToken;
}
};
// If already logged in show the home view
if (accessToken != null && Profile.getCurrentProfile()!=null) {
try {
Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
startActivity(intent);
finish();
}
catch (RuntimeException e) {
e.printStackTrace();
}
}
else {
databaseHelper.deleteAll();
}
}
private void getUserDetails(LoginResult loginResult) {
GraphRequest data_request = GraphRequest.newMeRequest(
accessToken, new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject json_object,
GraphResponse response) {
Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
intent.putExtra("userProfile", json_object.toString());
startActivity(intent);
finish();
}
});
Bundle permission_param = new Bundle();
permission_param.putString("fields", "id,name,email,picture.width(120).height(120),gender");
data_request.setParameters(permission_param);
data_request.executeAsync();
}
i have done this same.I did using webservice.
Pass the user details to backend and created response as retrieving the same user details back.Then I stored the response to sharedpreference.
private void loginSuccess(JSONObject mJsonObject) {
try {
Snackbar.make(fbLoginButton, "Successfully Loged in!", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
setSharedPreference(AppConstants.SharedKey.USER_ID, mJsonObject.getJSONObject(AppConstants.APIKeys.USER_DETAILS).getString(AppConstants.APIKeys.ID));
setSharedPreference(AppConstants.SharedKey.USER_NAME, mJsonObject.getJSONObject(AppConstants.APIKeys.USER_DETAILS).getString(AppConstants.APIKeys.USER_NAME));
setSharedPreference(AppConstants.SharedKey.USER_EMAIL, mJsonObject.getJSONObject(AppConstants.APIKeys.USER_DETAILS).getString(AppConstants.APIKeys.EMAIL));
setSharedPreference(AppConstants.SharedKey.LOGIN_STATUS, "true");
startActivity(new Intent(LoginActivity.this, HomeActivity.class));
this.finish();
} catch (JSONException e) {
e.printStackTrace();
}
}
Try this :)
In your onCompleted() do this
#Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
Log.e("GraphResponse", "-------------" + response.toString());
Log.e("fb_json", "-------------" + object.toString());
try {
if (object.has("id")) {
fb_id = object.getString("id");
}
if (object.has("name")) {
userName = object.getString("name");
}
if (object.has("email")) {
email = object.getString("email");
}
setSharedPreference(AppConstants.SharedKey.FB_ID, fb_id);
imageUrl = "http://graph.facebook.com/" + object.getString("id") + "/picture?type=large";
Log.e("profileImage", imageUrl);
new WebserviceCall(LoginActivity.this, AppConstants.Methods.fbLOgin).execute(new String[]{email, fb_id, userName, getSharedPreference(AppConstants.SharedKey.DEVICE_ID), "", imageUrl});
} catch (JSONException e) {
e.printStackTrace();
}
Then call webservice by passing fb_id,username,email etc and in the onPostexecute call loginSuccess(mJsonObject);
I'm trying to get name and email from facebook login.
I'm using: compile 'com.facebook.android:facebook-android-sdk:4.+'
I can get into onSuccess but the code does not get into GraphRequest and I think that's why I can't get name and email (I'd also like get Profile picture)
I got the autogenerated code (GraphRequest) from facebook developer Explorer Api Graph
public class LoginActivity
{
LoginButton buttonLoginFacebook;
#Nullable
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
buttonLoginFacebook = (LoginButton) findViewById(R.id.connectWithFbButton);
buttonLoginFacebook.setReadPermissions(Arrays.asList(
"public_profile", "email"));
FacebookSdk.setIsDebugEnabled(true);
FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
FacebookSdk.addLoggingBehavior(LoggingBehavior.REQUESTS);
buttonLoginFacebook.setOnClickListener(this);
buttonLoginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
//----->THE CODE JUMPS FROM HERE
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
mensajeFACEBOOK="TRYING TO GET NAME";
}
});
//----->TO HERE
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,first_name,last_name");
request.setParameters(parameters);
request.executeAsync();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
}
}
This is how i do it. Hope this helps.
private void registerCallBackMethod(){
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(final LoginResult loginResult) {
final String accessToken = loginResult.getAccessToken().getUserId();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject jsonObject,
GraphResponse response) {
// Getting FB User Data and checking for null
Bundle facebookData = getFacebookData(jsonObject);
String email = "";
String first_name = "";
String last_name = "";
String profile_pic = "";
if (facebookData.getString("email") != null && !TextUtils.isEmpty(facebookData.getString("email")))
email = facebookData.getString("email");
else
email = "";
if (facebookData.getString("first_name") != null && !TextUtils.isEmpty(facebookData.getString("first_name")))
first_name = facebookData.getString("first_name");
else
first_name = "";
if (facebookData.getString("last_name") != null && !TextUtils.isEmpty(facebookData.getString("last_name")))
last_name = facebookData.getString("last_name");
else
last_name = "";
if (facebookData.getString("profile_pic") != null && !TextUtils.isEmpty(facebookData.getString("profile_pic")))
profile_pic = facebookData.getString("profile_pic");
else
profile_pic = "";
sendValues(first_name+" "+last_name,email, "", "", accessToken, "Facebook",profile_pic);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,first_name,last_name,email,gender");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel () {
Log.d("TAG", "Login attempt cancelled.");
}
#Override
public void onError (FacebookException e){
e.printStackTrace();
Log.d("TAG", "Login attempt failed.");
deleteAccessToken();
}
}
);
}
private Bundle getFacebookData(JSONObject object) {
Bundle bundle = new Bundle();
try {
String id = object.getString("id");
URL profile_pic;
try {
profile_pic = new URL("https://graph.facebook.com/" + id + "/picture?type=large");
Log.i("profile_pic", profile_pic + "");
bundle.putString("profile_pic", profile_pic.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
bundle.putString("idFacebook", id);
if (object.has("first_name"))
bundle.putString("first_name", object.getString("first_name"));
if (object.has("last_name"))
bundle.putString("last_name", object.getString("last_name"));
if (object.has("email"))
bundle.putString("email", object.getString("email"));
if (object.has("gender"))
bundle.putString("gender", object.getString("gender"));
} catch (Exception e) {
Log.d("TAG", "BUNDLE Exception : "+e.toString());
}
return bundle;
}
private void deleteAccessToken() {
AccessTokenTracker accessTokenTracker = new AccessTokenTracker() {
#Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
if (currentAccessToken == null){
//User logged out
LoginManager.getInstance().logOut();
}
}
};
}
Actually GraphRequest.executeAsync() is an async method with a callback onCompleted so to read the data you need to do it inside the callback.
buttonLoginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
//Read the data you need from the GraphResponse here like this:
try {
String firstName = response.getJSONObject().getString("first_name");
String lastName = response.getJSONObject().getString("last_name");
String email = response.getJSONObject().getString("email");
String id = response.getJSONObject().getString("id");
String picture = response.getJSONObject().getJSONObject("picture").getJSONObject("data").getString("url");
} catch (JSONException e) {
e.printStackTrace();
}
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,first_name,last_name,picture.width(150).height(150)");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
Also included the profile picture field picture.width(150).height(150) as you asked
I implemented Facebook in app and fetched name,email and id from graph api,Now i cannot get email it from graph api and i passed id,name,email fields but got only id,name but not email.Is it change any privacy policy from facebook.
I'm Using https://graph.facebook.com/me?access_token=(token here)&fields=id,name,email
Try With This Running successfully
private void facebookLogin() {
mFaceBookloginButton = (LoginButton) findViewById(R.id.login_button);
mFaceBookloginButton.setReadPermissions("public_profile");
mFaceBookloginButton.setReadPermissions("email");
callbackManager = CallbackManager.Factory.create();
mFaceBookloginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
MyLog.debug("Name" + loginResult.getAccessToken(), ActivityLogin.class);
Profile profile = Profile.getCurrentProfile();
if (profile != null) {
MyLog.debug("Pic Url" + profile.getProfilePictureUri(200, 200), ActivityLogin.class);
MyLog.debug("User Name" + profile.getFirstName(), ActivityLogin.class);
MyLog.debug("User Email" + profile.getLastName(), ActivityLogin.class);
}
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
FacebookUser facebookUser = null;
try {
if (object != null) {
facebookUser = new FacebookUser();
if (object.has("id")) {
facebookUser.setId(object.getString("id"));
}
if (object.has("first_name")) {
facebookUser.setFirst_name(object.getString("first_name"));
}
if (object.has("last_name"))
facebookUser.setLast_name(object.getString("last_name"));
if (object.has("email"))
facebookUser.setEmail(object.getString("email"));
}
if (facebookUser != null) {
hitSocialLogin(facebookUser);
LoginManager.getInstance().logOut();
}
} catch (Exception e) {
MyLog.printException(e);
} finally {
LoginManager.getInstance().logOut();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id, first_name, last_name, email,gender, birthday, location"); // ParĂ¡metros que pedimos a facebook
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
MyLog.debug("on Cancel", ActivityLogin.class);
}
#Override
public void onError(FacebookException exception) {
MyLog.debug("on Cancel" + exception, ActivityLogin.class);
}
});
}
I imported latest facebook sdk in my ecllipe.When i am trying to get basic information in my app,it does n't import respective packages of Request,Response,and Session.what i do?to import respective packages.
I tried below code but facing problem at importing respective packages.
LoginActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Session.getActiveSession() == null
|| Session.getActiveSession().isClosed()) {
Session.openActiveSession(this, true, new StatusCallback() {
#Override
public void call(Session session, SessionState state,
Exception exception) {
System.out.println("State= " + state);
if (session.isOpened()) {
System.out.println("Token=" + session.getAccessToken());
Request.executeMeRequestAsync(session,
new GraphUserCallback() {
#Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
System.out.println("User=" + user);
}
if (response != null) {
System.out.println("Response="
+ response);
Toast.makeText(MainActivity.this,
response.toString(),
Toast.LENGTH_LONG).show();
}
}
});
}
if (exception != null) {
System.out.println("Some thing bad happened!");
exception.printStackTrace();
}
}
});
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
}
It happens with you because session is removed from new android SDK 4. So you cant not use this code for getting user information.
Try to use this code. It's work successfully for me.
First Initialize FacebookSdk in onCreate before inflecting layout.
FacebookSdk.sdkInitialize(this.getApplicationContext());
loginButton = (LoginButton) findViewById(R.id.login_button);
List < String > permissionNeeds = Arrays.asList("user_photos", "email",
"user_birthday", "public_profile", "AccessToken");
loginButton.registerCallback(callbackManager,
new FacebookCallback < LoginResult > () {#Override
public void onSuccess(LoginResult loginResult) {
System.out.println("onSuccess");
String accessToken = loginResult.getAccessToken()
.getToken();
Log.i("accessToken", accessToken);
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {#Override
public void onCompleted(JSONObject object,
GraphResponse response) {
Log.i("LoginActivity", response.toString());
try {
id = object.getString("id");
try {
URL profile_pic = new URL(
"http://graph.facebook.com/" + id + "/picture?type=large");
Log.i("profile_pic",
profile_pic + "");
} catch (MalformedURLException e) {
e.printStackTrace();
}
String name = object.getString("name");
String email = object.getString("email");
String gender = object.getString("gender");
String birthday = object.getString("birthday");
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields",
"id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
System.out.println("onCancel");
}
#Override
public void onError(FacebookException exception) {
System.out.println("onError");
Log.v("LoginActivity", exception.getCause().toString());
}
});
Add method.
#Override
protected void onActivityResult(int requestCode, int responseCode,
Intent data) {
super.onActivityResult(requestCode, responseCode, data);
callbackManager.onActivityResult(requestCode, responseCode, data);
}
How to get email id from facebook Login
permission added are
mFBLoginButton.setReadPermissions("user_friends");
mFBLoginButton.setReadPermissions("public_profile");
mFBLoginButton.setReadPermissions("email");
mFBLoginButton.setReadPermissions("user_birthday");
I am going through Facebook tutorial for login and to access email I am using GraphRequest code is as below
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me?fields=email",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
if (response != null)
Log.d(TAG, " response " + response.toString());
}
}
).executeAsync();
but I am not getting email in the response.
could some one help me please
you need to asking for the permissions` using the parameter while logging in to grab permissions, you must also consider the fact that not every logged in user has an email assigned to their account also permissions to access it.
one can open and verify their facebook accounts using their Mobile numbers, hence the probability that no email exists in your account.
hope this info helps!
As 'Md Abdul Gafur' mentioned make sure your facebook account is properly setup.
Add the dependency to your build.gradle:
compile 'com.facebook.android:facebook-android-sdk:4.2.0'
Add the facebook activity to your AndroidManifest.xml:
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
Then in your actvitiy override onActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
Login from your activity with:
FacebookSdk.sdkInitialize(mContext.getApplicationContext());
FacebookSdk.setApplicationId(mApiKey);
mCallbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject user, GraphResponse response) {
if (response.getError() != null) {
// handle error
} else {
if (user != null) {
// Get the data you need
String email = user.optString("email", "");
} else {
//handle null user
}
}
}
});
request.executeAsync();
}
#Override
public void onCancel() {
//handle cancel
}
#Override
public void onError(FacebookException exception) {
// handle exception
}
});
LoginManager.getInstance().logInWithReadPermissions(mContext, Collections.singletonList("public_profile"));
Use this code. it's works successfully. You can get all user data by this.
loginButton = (LoginButton) findViewById(R.id.login_button);
List < String > permissionNeeds = Arrays.asList("user_photos", "email",
"user_birthday", "public_profile", "AccessToken");
loginButton.registerCallback(callbackManager,
new FacebookCallback < LoginResult > () {#Override
public void onSuccess(LoginResult loginResult) {
System.out.println("onSuccess");
String accessToken = loginResult.getAccessToken()
.getToken();
Log.i("accessToken", accessToken);
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {#Override
public void onCompleted(JSONObject object,
GraphResponse response) {
Log.i("LoginActivity", response.toString());
try {
id = object.getString("id");
try {
URL profile_pic = new URL(
"http://graph.facebook.com/" + id + "/picture?type=large");
Log.i("profile_pic",
profile_pic + "");
} catch (MalformedURLException e) {
e.printStackTrace();
}
name = object.getString("name");
email = object.getString("email");
gender = object.getString("gender");
birthday = object.getString("birthday");
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields",
"id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
System.out.println("onCancel");
}
#Override
public void onError(FacebookException exception) {
System.out.println("onError");
Log.v("LoginActivity", exception.getCause().toString());
}
});