I am using Facebook SDK for Android to allow users to register and use app. I want to get some basic info about user like user name and email. Anyway, I have problem because
Get the permissions first
private static final List<String> PERMISSIONS = Arrays.asList(
"email","user_location");
The Method for getting the user information
Session.openActiveSession(RegisterActivity.this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state,
Exception exception) {
/*
* Session.getActiveSession().onActivityResult(activity1,64206,
* -1,activity1.getIntent());
*/
if (session.isOpened()) {
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
RegisterActivity.this, PERMISSIONS);
session.requestNewReadPermissions(newPermissionsRequest);
return;
}
// make request to the /me API
Request.newMeRequest(session, new GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// TODO Auto-generated method stub
Log.d("",""+user);
try {
name=user.getName();
email=user.getProperty("email").toString();
location=(user.getLocation().getProperty("name").toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).executeAsync();
}
}
});
isSubsetof method
private boolean isSubsetOf(Collection<String> subset,
Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}
put this code in onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("Activity result"," "+requestCode+" "+resultCode+" "+data.toString());
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
}
Put Internet permission in Manifest
<uses-permission android:name="android.permission.INTERNET" />
Declare Facebook Login Activity in manifest
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
hey you can try this way...
session.openForRead(new Session.OpenRequest(this).setPermissions(Arrays.asList("id", "name", "picture","installed" )).setCallback(statusCallback));