java - 无法获取专辑列表

标签 java gdata-api google-data-api picasa

我想从我的 Google Picasa 帐户中获取相册列表。我试过 this指导。问题是它验证成功但不返回任何相册(请参阅下面我的代码)。我仍然可以发布新专辑。

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

这是控制台输出:

0
TripToFrance03

最佳答案

您可能缺少类路径中的 gdata-photos-meta-2.0.jar。代码将在没有该 jar 的情况下编译和运行,但 getAlbumEntries() 不会返回任何内容。

关于java - 无法获取专辑列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10385115/

相关文章:

java - EventHandler 作为匿名内部类实现

java - JComboBox 记住其他选择

android - 尝试使用 gdata API 将视频上传到 YouTube 时找不到类错误

c# - 如何获得长期访问 token Google API

java - 如何在覆盖文件之前检查文件是否为空?

java - Java中字符串池的底层机制?

ios - 如何在 iOS 上使用 Google Drive API 处理电子表格

java - gdata-java-client 和 google-api-java-client 有什么区别?

iphone - 在 iPhone 应用程序中进行 Google 搜索

javascript - 在 Google Visualization API 中使用 Group By Aggregation 保留格式