Click here to Skip to main content
12,817,318 members (35,153 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


10 bookmarked
Posted 21 Nov 2013

Get Photo Albums from Facebook and Twitter in Android

, 21 Nov 2013 MIT
Rate this:
Please Sign up or sign in to vote.
Get photo albums from Facebook and Twitter in Android.


While creating photo apps in Android, it is a frequent requirement to access photo albums from Facebook and Twitter. Although there are SDKs to provide these functionalities but there implementation is cumbersome. An open source SDK available that is easy to use and allows integrating with not only Facebook and Twitter but also with several social networks. This SDK is SocialAuth Android SDK. The SDK helps you to get albums from Facebook and Twitter in a simple way along with examples.

Facebook stores all the posted images in form of PhotoAlbums but Twitter not support this mechanism. Therefore for Twitter, the API searches last 100 tweets from people you are following and create an album for it. For example, suppose you are following Maxim. The API will create an album with the name Maxim and load all images posted by Maxim in that album.

Getting Started

First you need to register your application with the social provider you need to integrate, and get the API keys and secrets. The following links will help you to get the API keys and secrets:

Integrating SDK

Now we can start integrating the SDK which can be downloaded from This SDK contains the Java libraries that do the heavy lifting of OAuth as well as the REST calls for each social provider. Extract the contents and we are all set.

  • Copy libs/socialauth-android-3.0.jar and libs/socialauth4.3 jar into the libs folder of your application. If you have latest ADT, jars will be automatically added to your build path else you need to manually add the jar files in build path. We recommend you to upgrade to the latest ADT.
  • Copy the assets/ file to the assets folder of your application. The file is used by the SDK for the keys and secrets. Replace the default keys and secrets with your keys and secrets that were obtained above.
  • Add android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE in manifest.

That is all you need to get started. The SDK zip file also contains code samples which can help you go ahead with the coding.  



Initialize SocialAuthAdapter Object and create a Facebook /Twitter button. On clicking the button authorize the adapter. The code show how to authorize the adapter for Twitter:

public void  onCreate(Bundle savedInstanceState) {

    adapter = new SocialAuthAdapter(new ResponseListener());
    twitter_button = (Button)findViewById(;

    twitter_button.setOnClickListener(new OnClickListener() 
        public void onClick(View v) 
            adapter.authorize(ProviderUI.this, Provider.TWITTER);

Getting UserAlbums

After authentication, you will receive response in ResponseListener. Here you can initiate call to get user albums by getAlbumsAsync() method and receive response in albumDataListener. You can get album name, cover photo, photos count , array of images with their name and URLs.

private final class ResponseListener implements DialogListener 
  public void onComplete(Bundle values) {
  adapter.getAlbumsAsync(new AlbumDataListener());   

// To receive the album response after authentication

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

public void onExecute(List<Album> t) {

  Log.d("Custom-UI", "Receiving Data");
  List<Album> albumList = t;
  if (albumList != null && albumList.size() > 0) {

  // 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());

  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());

This same code work for Facebook too. You just need to use Provider.Facebook to load albums from Facebook.


To download the SDK and examples, please visit:


This article, along with any associated source code and files, is licensed under The MIT License


About the Author

India India
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionEmpty Image list returned from facebook Pin
Sanjay Sah14-Oct-15 22:37
memberSanjay Sah14-Oct-15 22:37 
QuestionFacebook not working Pin
vikrant saini28-Jan-14 1:37
membervikrant saini28-Jan-14 1:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 21 Nov 2013
Article Copyright 2013 by 3PillarLabs
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid