2012-04-30 3 views
3

내 Google Picasa 계정에서 앨범 목록을 가져오고 싶습니다. 나는 this 가이드를 시도했다. 문제는 인증에 성공했지만 은 어떤 앨범도 반환하지 않습니다. (아래 코드 참조). 나는 아직도 새로운 앨범을 올릴 수있다.앨범 목록을 가져올 수 없습니다.

0 
TripToFrance03 

답변

5

당신은 아마 누락 gdata-photos-meta-2.0.jar 클래스 패스에서 :

import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URL; 
import java.util.List; 

import com.google.gdata.client.photos.PicasawebService; 
import com.google.gdata.data.PlainTextConstruct; 
import com.google.gdata.data.photos.AlbumEntry; 
import com.google.gdata.data.photos.UserFeed; 
import com.google.gdata.util.AuthenticationException; 
import com.google.gdata.util.ServiceException; 

public class Test { 
    public static void main(String[] args) { 
     String username = "myusername"; 
     String password = "mypassword"; 
     PicasawebService service = new PicasawebService("myapp"); 
     try { 
      // Get list of albums. (AUTHENTICATION SUCCESSFUL BUT NO ALBUM RETURNED) 
      service.setUserCredentials(username, password); 
      URL url = new URL("https://picasaweb.google.com/data/feed/api/user/" + username + "?kind=album"); 
      UserFeed feed = service.getFeed(url, UserFeed.class);   
      List<AlbumEntry> albums = feed.getAlbumEntries(); 
      System.out.println(albums.size()); 

      // Create an album. (SUCCESSFUL, I CAN SEE IT IN MY PICASA) 
      URL postUrl = new URL("https://picasaweb.google.com/data/feed/api/user/" + username); 
      AlbumEntry myAlbum = new AlbumEntry(); 
      myAlbum.setTitle(new PlainTextConstruct("Trip to France")); 
      myAlbum.setDescription(new PlainTextConstruct("My recent trip to France was delightful!")); 
      AlbumEntry insertedEntry = service.insert(postUrl, myAlbum); 
      System.out.println(insertedEntry.getName()); 
     } catch (AuthenticationException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (MalformedURLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (ServiceException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     }  
    } 
} 

이 콘솔 출력입니다. 코드는 jar없이 컴파일되고 실행되지만 getAlbumEntries()은 아무 것도 반환하지 않습니다.