我徒劳地寻找了一个很好的例子或起点来编写一个基于 java 的 facebook 应用程序......我希望这里有人会知道一个。同样,我听说 facebook 将不再支持他们的 java API,这是真的吗?如果是,这是否意味着我们不应该再使用 java 来编写 facebook 应用程序?
6 回答
有一个社区项目旨在使 Facebook Java API 保持最新,使用旧的官方 Facebook 代码作为起点。
您可以在此处找到它以及入门指南和一些示例代码。
我使用 facebook java api编写了一个示例 它使用 FacebookXmlRestClient 来发出客户端请求并打印所有用户信息 http://programmaremobile.blogspot.com/2009/01/facebook-java-apieng.html
BatchFB 提供了一个现代 Java API,让您可以轻松地将 Facebook 调用优化到最低限度:
http://code.google.com/p/batchfb/
以下是您可以在单个 FB 请求中有效执行的操作的主页示例:
/** You write your own Jackson user mapping for the pieces you care about */
public class User {
long uid;
@JsonProperty("first_name") String firstName;
String pic_square;
String timezone;
}
Batcher batcher = new FacebookBatcher(accessToken);
Later<User> me = batcher.graph("me", User.class);
Later<User> mark = batcher.graph("markzuckerberg", User.class);
Later<List<User>> myFriends = batcher.query(
"SELECT uid, first_name, pic_square FROM user WHERE uid IN" +
"(SELECT uid2 FROM friend WHERE uid1 = " + myId + ")", User.class);
Later<User> bob = batcher.queryFirst("SELECT timezone FROM user WHERE uid = " + bobsId, User.class);
PagedLater<Post> feed = batcher.paged("me/feed", Post.class);
// No calls to Facebook have been made yet. The following get() will execute the
// whole batch as a single Facebook call.
String timezone = bob.get().timezone;
// You can just get simple values forcing immediate execution of the batch at any time.
User ivan = batcher.graph("ivan", User.class).get();
You might want to try Spring Social. It might be limited in terms of Facebook features, but lets you also connect to Twitter, LinkedIn, TripIt, GitHub, and Gowalla.
The other side of things is that as Facebook adds features some of the old API's might break, so using a simpler pure FB api (that you can update when things don't work) might be a good idea.
This tutorial will literally step you through everything you need to do: http://ocpsoft.org/opensource/creating-a-facebook-app-setup-and-tool-installation/
It comes in 3 parts. The other 2 are linked from there.