2012-05-08 63 views
0

我正在製作一個應用程序,我想在其中瀏覽臉書的所有相冊。我爲它使用了以下教程。無法瀏覽Android中的臉書相冊

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

但沒能獲得單一的數據。我收到來自Facebook服務器的空響應。

任何人都可以幫我獲取Facebook相冊及其照片嗎?

這是我的代碼。

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; 
     } 
    } 

回答

2

你掛不包括任何認證或登錄代碼,據我可以告訴教程 - 我不知道到什麼程度,你已經實現了這一點。從你的代碼,與訪問令牌添加「手動」它看起來並不像你所使用的Facebook Android SDK對用戶進行認證,並登錄了她。

These examples包括使用SDK做Android上的身份驗證/登錄碼。

您需要向用戶索要「user_photos」權限才能成功請求相冊數據。

你驗證和登錄的用戶後,可以通過調用

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

其中AlbumRequestListener擴展SDK的RequestListener檢索專輯。