How to get the facebook photo using SocialOath?

Hello Friends,
I am using the SocailOath to connect with facebook and want to get the photo from facebook album..I used the below code to get the Photo from the facebook..I am not getting any crash in my application…My prpblem is only that i am not getting the facebook album photo..If there any grammatical error in my questuin than please pardon me..Thanks in Advancae

package com.tv.socail;
import java.util.List;
import org.brickred.socialauth.Album;
import org.brickred.socialauth.Photo;
import org.brickred.socialauth.Profile;
import org.brickred.socialauth.android.DialogListener;
import org.brickred.socialauth.android.SocialAuthAdapter;
import org.brickred.socialauth.android.SocialAuthAdapter.Provider;
import org.brickred.socialauth.android.SocialAuthError;
import org.brickred.socialauth.android.SocialAuthListener;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.tv.sociallogin.R;

public class Logins extends Activity implements OnClickListener {

private Button fbConnect = null;

String socialId="";
String socialType="";
private String providerName;
private static SocialAuthAdapter adapter;

private final Provider[] providers = new Provider[] { Provider.FACEBOOK,
        Provider.TWITTER, Provider.LINKEDIN, Provider.GOOGLEPLUS };


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.logins);

    fbConnect = (Button)findViewById(R.id.fbConnect);

    fbConnect.setOnClickListener(this);


    adapter = new SocialAuthAdapter(new ResponseListener());



}


private final class ResponseListener implements DialogListener {

    @Override
    public void onComplete(Bundle values) {

        Log.d("Custom-UI", "Successful");




        // Get the provider
        providerName = values.getString(SocialAuthAdapter.PROVIDER);

        Log.d("Custom-UI", "providername = " + providerName);

        // Toast.makeText(MainScreen.this, providerName + " connected",
        // Toast.LENGTH_SHORT).show();

        int res = getResources().getIdentifier(providerName + "_array",
                "array", Logins.this.getPackageName());
        //adapter.getUserProfileAsync(new ProfileDataListener());
        adapter.getAlbumsAsync(new AlbumDataListener()); 


    }

    @Override
    public void onError(SocialAuthError error) {
        Log.d("Custom-UI", "Error");
        error.printStackTrace();
    }

    @Override
    public void onCancel() {
        Log.d("Custom-UI", "Cancelled");
    }

    @Override
    public void onBack() {
        Log.d("Custom-UI", "Dialog Closed by pressing Back Key");

    }
}


private final class ProfileDataListener implements
 SocialAuthListener<Profile> {

    @Override
    public void onExecute(String provider, Profile t) {

        Log.d("Custom-UI", "Receiving Data");

        Profile profileMap = t;

        //String emailId=profileMap.getEmail();
        socialId=profileMap.getValidatedId();
        socialType=profileMap.getProviderId();


    }

    @Override
    public void onError(SocialAuthError e) {

    }
}

private final  class AlbumDataListener implements  SocialAuthListener<List<Album>>
{

    @Override
    public void onError(SocialAuthError arg0) {
        // TODO Auto-generated method stub
        System.out.println("I AM eroor");
    }

    @Override
    public void onExecute(String arg0,List<Album> t) {

        Log.d("Custom-UI", "Receiving Data");
        List<Album> albumList = t;

        System.out.println("I AM OUSIDE"+t.size());// HERE I AM GETTING THE ALBUM SIZE IS ZERO..

        if (albumList != null && albumList.size() > 0) {

            System.out.println("I AM INSIDE"+t.size());
            // Get Photos inside Album

            for (Album a : albumList) {
                Log.d("Custom-UI", "Album ID = " + a.getId());
                Log.d("Custom-UI", "Album Name = " + a.getName());
                Log.d("Custom-UI", "Cover Photo = " + a.getCoverPhoto());
                Log.d("Custom-UI", "Photos Count = " + a.getPhotosCount());

                List<Photo>photosList = a.getPhotos();

                if (photosList != null && photosList.size() > 0) {

                    for (Photo p : photosList) {

                        Log.d("Custom-UI", "Photo ID = " + p.getId());
                        Log.d("Custom-UI", "Name    = " + p.getTitle());
                        Log.d("Custom-UI", "Thumb Image =" + p.getThumbImage());
                        Log.d("Custom-UI", "Small Image =" + p.getSmallImage());
                        Log.d("Custom-UI", "Medium Image =" + p.getMediumImage());
                        Log.d("Custom-UI", "Large Image = " + p.getLargeImage());
                    }}
            }}
    }


}
@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.fbConnect:

        // This method will enable the selected provider
        try {
            adapter = null;
            adapter = new SocialAuthAdapter(new ResponseListener());


            adapter.addConfig(Provider.FACEBOOK, "4918105455190972737",
                    "09897721dsde61b95fa22869096da63d2ef", null);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        adapter.authorize(Logins.this, Provider.FACEBOOK);

        break;

    default:
        break;
     }
    }
   }


Source: facebook

Leave a Reply