Skip to content
This repository has been archived by the owner on Aug 3, 2019. It is now read-only.

Get profile

Roman Kushnarenko edited this page Jun 20, 2015 · 2 revisions

Facebook doesn't reveal all user fields by default. For example, if you need picture, then you need to specify it in your graph api request. I can understand this, since getting all possible user fields will be time consuming task and this is not what we want.
Thus, two options are possible to get profile data.

Default

By using this way, you can get many properties like: id, name, education and more. Just ensure to have needed permissions. Read the javadoc to know what is needed. But, here you won't be able to get several properties like: cover, picture and other.

Initialize callback listener:

OnProfileListener onProfileListener = new OnProfileListener() {			
	@Override
	public void onComplete(Profile profile) {
		Log.i(TAG, "My profile id = " + profile.getId());
	}

	/* 
	 * You can override other methods here: 
	 * onThinking(), onFail(String reason), onException(Throwable throwable)
	 */		
};

Get the profile:

mSimpleFacebook.getProfile(onProfileListener);

Be specific and get what you need

By using this option, you define the properties you need, and you will get only them. Here, any property is possible to get.

Prepare the properties that you need:

Profile.Properties properties = new Profile.Properties.Builder()
	.add(Profile.Properties.ID)
	.add(Profile.Properties.FIRST_NAME)
	.add(Profile.Properties.COVER)
	.add(Profile.Properties.WORK)
	.add(Profile.Properties.EDUCATION)
	.add(Profile.Properties.PICTURE)
	.build();

Get the profile:

mSimpleFacebook.getProfile(properties, onProfileListener);

Be even more specific - Picture Attributes

You can describe the picture you really need like: small, normal, large, square and set width and height.

Prepare specific picture that you need:

PictureAttributes pictureAttributes = Attributes.createPictureAttributes();
pictureAttributes.setHeight(500);
pictureAttributes.setWidth(500);
pictureAttributes.setType(PictureType.SQUARE);

Prepare the properties that you need:

Profile.Properties properties = new Profile.Properties.Builder()
	.add(Properties.ID)
	.add(Properties.FIRST_NAME)
	.add(Properties.PICTURE, pictureAttributes)
	.build();			

Get the profile:

mSimpleFacebook.getProfile(properties, onProfileListener);
Clone this wiki locally