简体   繁体   中英

Not able to browsing the facebook albums in android

I am making one application in which I want to browse all the albums of facebook. I used the following tutorial for it.

http://huguesjohnson.com/programming/java/android-fb-album/

But not able to get the single data. I am getting null response from the facebook server.

Can anyone help me to get facebook albums and its photos?

Here is my code.

public class getUserImages extends AsyncTask<Void, Void, Void>
    {
        @Override
        protected Void doInBackground(Void... params) 
        {
            try
            {
             //invoke the API to get albums
              long startTime=System.currentTimeMillis();
              RestClient client = new RestClient("https://graph.facebook.com/" + PreferenceData.getUserId(FacebookIntegrationActivity.this) + "/albums?access_token="+mFacebook.getAccessToken());
              String albumsJson=client.execute(0);
              long endTime=System.currentTimeMillis();
              Log.d("==","Time to download albums="+(endTime-startTime)+"ms");
              Log.d("==","Album Json="+albumsJson);
            }
            catch (Exception e) 
            {
                e.printStackTrace();
            }
            return null;
        }
    }

The tutorial you've linked to doesn't include any authentication or login code as far as I can tell - I don't know to what extent you've implemented this. From your code, with the access token added 'manually' it doesn't look like you are using the Facebook Android SDK to authenticate the user and log her in.

These examples include code that use the SDK to do auth/login on Android.

You need to ask for the "user_photos" permission from the user to be able to request album data successfully.

After you've authenticated and logged in the user, you can retrieve the albums by calling

mFacebookAsyncRunner.request(USER_ID+"/albums",new AlbumRequestListener());

where AlbumRequestListener extends the SDK's RequestListener.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM