Browse Month: May 2014

How to Login via Facebook,get facebook friendlist and their details, post on friends wall and get newsfeeds details

How to Login with Facebook:

follow the below steps to add login via facebook:

step1: register app on

step 2: get the app_id , add it to strings file and add following code to manifest file:



android:value=”@string/app_id” />

//add meta-data inside appication tag.

<activity android:name=”com.facebook.LoginActivity” >

step 3: Download latest facebooksdk and import it as project in your project

step 4: add following code onclick of login with facebook button:

try {

PackageInfo info = getPackageManager().getPackageInfo( “package_name”, PackageManager.GET_SIGNATURES);

for (Signature signature : info.signatures)


MessageDigest md = MessageDigest.getInstance(“SHA”); md.update(signature.toByteArray());

Log.d(“KeyHash:”, Base64.encodeToString(md.digest(), Base64.DEFAULT));


} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
} //


//Get keyhash from above code and add it to developers.facebook in your project
session1 = Session.getActiveSession();

if (session1 == null)

{ session1 = new Session(Login.this);


if (session1.getState().equals( SessionState.CREATED_TOKEN_LOADED))


session1.openForRead(new Session.OpenRequest(Login.this) .setCallback(statusCallback));

access_token = session1.getAccessToken();



if (!session1.isOpened() && !session1.isClosed())


session1.openForRead(new Session.OpenRequest(Login.this) .setCallback(statusCallback));

access_token = session1.getAccessToken();

} else


Session.openActiveSession(Login.this, true, statusCallback);

access_token = session1.getAccessToken();



/// Add this method to your code:

private Session.StatusCallback statusCallback = new Session.StatusCallback() {
@Override public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

public void onCompleted(GraphUser user, Response response) {
if (user != null) {


fbid = user.getId();

fbname = user.getName();
} } });
} }


//override this method of activity:

@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

Session.getActiveSession() .onActivityResult(this, requestCode, resultCode, data);



–>How to Get Facebook friendlist:

Create async task and use below url to get facebookfriend list:”session access_token”

Note: parse the data using Json .

–>How to share on friends wall:

add below code to share on friends wall:

private void publishFeedDialog(int position) {


Bundle params = new Bundle();

params.putString(“message”,”YOUR MESSAGE” );

params.putString(“to”,”Friends userid”);

WebDialog feedDialog = (   new WebDialog.FeedDialogBuilder(Context,  Session.getActiveSession(),    params))                .setOnCompleteListener(null)   .build();;

} catch(Exception e){

e.printStackTrace(); }



–> How to Get NewsFeed:

Use below url to get newsfeed:


Note: use Json parsing to retrive details of each newsfeed.


Loading image from url using AQuery

Download android-query.jar from below link:


Add following code where you want to load image :

public ImageLoader imageLoader;

imageLoader = new ImageLoader(this);

AQuery androidAQuery=new AQuery(getApplicationContext());, true, true, 100,default_pic);


Note: if you dont want to store image in cache memory set true parameters to false.



Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box