# RestFB (http://restfb.com)
## What it is
RestFB is a pure Java Facebook Graph API and Old REST API client with no external dependencies.
## Licensing
RestFB uses other open-source software - see the "licensing" directory.
RestFB itself is open source software released under the terms of the MIT License.
## Installation
RestFB is a single JAR - just drop `restfb-1.6.11.jar` into your app and you're ready to go.
Or, if you're using [Maven](http://maven.apache.org/), you can add RestFB to your project like this:
```xml
<dependency>
<groupId>com.restfb</groupId>
<artifactId>restfb</artifactId>
<version>1.6.11</version>
</dependency>
```
## Building it Yourself
Just type
ant dist
...and you're done.
## Usage examples
Please see http://restfb.com for complete documentation.
#### Initialization
```java
// DefaultFacebookClient is the FacebookClient implementation
// that ships with RestFB. You can customize it by passing in
// custom JsonMapper and WebRequestor implementations, or simply
// write your own FacebookClient instead for maximum control.
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
// It's also possible to create a client that can only access
// publicly-visible data - no access token required.
// Note that many of the examples below will not work unless you supply an access token!
FacebookClient publicOnlyFacebookClient = new DefaultFacebookClient();
```
#### Fetching Single Objects
```java
// For all API calls, you need to tell RestFB how to turn the JSON
// returned by Facebook into Java objects. In this case, the data
// we get back should be mapped to the User and Page types, respectively.
// You can write your own types too!
User user = facebookClient.fetchObject("me", User.class);
Page page = facebookClient.fetchObject("cocacola", Page.class);
out.println("User name: " + user.getName());
out.println("Page likes: " + page.getLikes());
```
#### Fetching Multiple Objects in One Call
```java
FetchObjectsResults fetchObjectsResults =
facebookClient.fetchObjects(Arrays.asList("me", "cocacola"), FetchObjectsResults.class);
out.println("User name: " + fetchObjectsResults.me.getName());
out.println("Page likes: " + fetchObjectsResults.page.getLikes());
...
// Holds results from a "fetchObjects" call.
// You need to write this class yourself!
public class FetchObjectsResults {
@Facebook
User me;
// If the Facebook property name doesn't match
// the Java field name, specify the Facebook field name in the annotation.
@Facebook("cocacola")
Page page;
}
```
#### Fetching Connections
```java
Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);
Connection<Post> myFeed = facebookClient.fetchConnection("me/feed", Post.class);
out.println("Count of my friends: " + myFriends.getData().size());
out.println("First item in my feed: " + myFeed.getData().get(0));
// Connections support paging and are iterable
for (List<Post> myFeedConnectionPage : myFeed)
for (Post post : myFeedConnectionPage)
out.println("Post: " + post);
```
#### Searching
```java
// Searching is just a special case of fetching Connections -
// all you have to do is pass along a few extra parameters.
Connection<Post> publicSearch =
facebookClient.fetchConnection("search", Post.class,
Parameter.with("q", "watermelon"), Parameter.with("type", "post"));
Connection<User> targetedSearch =
facebookClient.fetchConnection("me/home", User.class,
Parameter.with("q", "Mark"), Parameter.with("type", "user"));
out.println("Public search: " + publicSearch.getData().get(0).getMessage());
out.println("Posts on my wall by friends named Mark: " + targetedSearch.getData().size());
```
#### Fetching Insights
```java
// Fetching Insights data is as simple as fetching a Connection
Connection<Insight> insights = facebookClient.fetchConnection("PAGE_ID/insights", Insight.class);
for (Insight insight : insights.getData())
out.println(insight.getName());
```
#### Executing FQL Queries
```java
String query = "SELECT uid, name FROM user WHERE uid=220439 or uid=7901103";
List<FqlUser> users = facebookClient.executeQuery(query, FqlUser.class);
out.println("Users: " + users);
...
// Holds results from an "executeQuery" call.
// You need to write this class yourself!
// Be aware that FQL fields don't always map to Graph API Object fields.
public class FqlUser {
@Facebook
String uid;
@Facebook
String name;
@Override
public String toString() {
return String.format("%s (%s)", name, uid);
}
}
```
#### Metadata/Introspection
```java
// You can specify metadata=1 for many calls, not just this one.
// See the Facebook Graph API documentation for more details.
User userWithMetadata =
facebookClient.fetchObject("me", User.class, Parameter.with("metadata", 1));
out.println("User metadata: has albums? "
+ userWithMetadata.getMetadata().getConnections().hasAlbums());
```
#### Passing Parameters
```java
// You can pass along any parameters you'd like to the Facebook endpoint.
Date oneWeekAgo = new Date(currentTimeMillis() - 1000L * 60L * 60L * 24L * 7L);
Connection<Post> filteredFeed = facebookClient.fetchConnection("me/feed", Post.class,
Parameter.with("limit", 3), Parameter.with("until", "yesterday"),
Parameter.with("since", oneWeekAgo));
out.println("Filtered feed count: " + filteredFeed.getData().size());
```
#### Selecting Specific Fields
```java
User user = facebookClient.fetchObject("me", User.class,
Parameter.with("fields", "id, name"));
out.println("User name: " + user.getName());
```
#### Getting Any Kind of Data as a JSON Object
```java
// Sometimes you can't know field names at compile time
// so the @Facebook annotation can't be used.
// Or maybe you'd like full control over the data that gets returned.
// Either way, RestFB has you covered. Just map any API call to JsonObject.
// Here's how to fetch a single object
JsonObject btaylor = facebookClient.fetchObject("btaylor", JsonObject.class);
out.println(btaylor.getString("name"));
// Here's how to fetch a connection
JsonObject photosConnection = facebookClient.fetchObject("me/photos", JsonObject.class);
String firstPhotoUrl = photosConnection.getJsonArray("data").getJsonObject(0).getString("source");
out.println(firstPhotoUrl);
// Here's how to handle an FQL query
String query = "SELECT uid, name FROM user WHERE uid=220439 or uid=7901103";
List<JsonObject> queryResults = facebookClient.executeQuery(query, JsonObject.class);
out.println(queryResults.get(0).getString("name"));
// Sometimes it's helpful to use JsonMapper directly if you're working with JsonObjects.
List<String> ids = new ArrayList<String>();
ids.add("btaylor");
ids.add("http://www.imdb.com/title/tt0117500/");
// First, make the API call...
JsonObject results = facebookClient.fetchObjects(ids, JsonObject.class);
// ...then pull out raw JSON data and map each type "by hand".
// Normally your FacebookClient uses a JsonMapper internally, but
// there's nothing stopping you from using it too!
JsonMapper jsonMapper = new DefaultJsonMapper();
User user = jsonMapper.toJavaObject(results.getString("btaylor"), User.class);
Url url = jsonMapper.toJavaObject(results.getString("http://restfb.com"), Url.class);
out.println("User is " + user);
out.println("URL is " + url);
```
#### Publishing a Message and Event
```java
// Publishing a simple message.
// FacebookType represents any Facebook Graph Object that has an ID property.
FacebookType publishMessageResponse =
facebookClient.publish("me/feed", FacebookType.class,
Parameter.with("message", "RestFB test"));
out.println("Published message ID: " + publishMessageResponse.getId());
// Publishing an event
Date tomorrow = new Date(currentTimeMillis() + 1000L * 60L * 60L * 24L);
Date twoDaysFromNow = new Date(currentTimeMillis() + 1000L * 60L * 60L * 48L);
FacebookType publishEventResponse = facebookClient.publish("me/events", FacebookTy
没有合适的资源?快使用搜索试试~ 我知道了~
小程序 Facebook API 的 Java 封装请求处理组件 RestFB(源码).zip
共150个文件
java:91个
json:25个
png:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 143 浏览量
2023-02-03
13:24:34
上传
评论
收藏 1.34MB ZIP 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
小程序 Facebook API 的 Java 封装请求处理组件 RestFB(源码).zip (150个子文件)
CHANGELOG 19KB
.classpath 495B
javadoc.css 7KB
style.css 5KB
angry-birds-friends.gif 5KB
.gitignore 36B
index.html 52KB
legacy-rest-api.html 24KB
overview.html 408B
JsonObject.java 48KB
DefaultFacebookClient.java 31KB
DefaultJsonMapper.java 30KB
JsonArray.java 29KB
InsightUtilsTest.java 23KB
FacebookType.java 20KB
FacebookClient.java 19KB
Post.java 19KB
DefaultLegacyFacebookClient.java 19KB
User.java 17KB
InsightUtils.java 17KB
ReflectionUtils.java 15KB
BaseFacebookClient.java 14KB
JsonMapperToJavaTest.java 13KB
BatchRequest.java 12KB
DefaultWebRequestor.java 12KB
LegacyFacebookClient.java 11KB
JsonTokener.java 10KB
GraphReaderExample.java 10KB
JsonWriter.java 9KB
Photo.java 8KB
JsonMapperToJsonTest.java 8KB
Page.java 8KB
Connection.java 7KB
LegacyExample.java 7KB
StringUtils.java 7KB
Checkin.java 7KB
Parameter.java 6KB
DateUtils.java 6KB
UrlUtils.java 6KB
Conversation.java 6KB
JsonMapper.java 5KB
Video.java 5KB
StatusMessage.java 4KB
WebRequestor.java 4KB
GraphPublisherExample.java 4KB
Event.java 4KB
Album.java 4KB
Comment.java 4KB
AppRequest.java 3KB
BinaryAttachment.java 3KB
Location.java 3KB
FacebookClientTest.java 3KB
Note.java 3KB
Venue.java 3KB
BatchResponse.java 3KB
Link.java 3KB
FacebookNetworkException.java 3KB
JsonStringer.java 3KB
FacebookGraphException.java 3KB
Group.java 3KB
ClasspathWebRequestor.java 3KB
JsonMapperErrorSwallowingTest.java 3KB
Question.java 3KB
FacebookResponseStatusException.java 3KB
BatchHeader.java 3KB
DateUtilsTest.java 3KB
TestUser.java 3KB
LegacyExample.java 3KB
FacebookOAuthException.java 3KB
SpecialCommentHandlingTest.java 2KB
QuestionOption.java 2KB
Insight.java 2KB
Message.java 2KB
AbstractJsonMapperTests.java 2KB
UrlUtilsTest.java 2KB
LegacyStreamPublishExample.java 2KB
FacebookQueryParseException.java 2KB
FacebookExceptionMapper.java 2KB
Application.java 2KB
Url.java 2KB
FacebookJsonMappingException.java 2KB
FacebookException.java 2KB
Place.java 2KB
FriendList.java 2KB
PageConnection.java 2KB
FacebookResponseContentException.java 2KB
NamedFacebookType.java 2KB
CategorizedFacebookType.java 2KB
Facebook.java 2KB
Account.java 2KB
Example.java 2KB
package-info.java 2KB
package-info.java 2KB
package-info.java 2KB
PrivateUser.java 1KB
package-info.java 1KB
package-info.java 1KB
package-info.java 1KB
JsonString.java 702B
JsonException.java 665B
共 150 条
- 1
- 2
资源评论
大富大贵7
- 粉丝: 393
- 资源: 8870
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- CO2半自动焊接小车在电力变压器油箱制造中的应用.pdf
- CO2焊接飞溅产生原因与防止方法探究.pdf
- CO2焊接在起重机轨道焊接中的应用.pdf
- 基于智慧医疗系统—全部资料+高分项目+详细文档.zip
- 基于智慧医院信息管理系统HIS 全部资料+高分项目+详细文档.zip
- CO2气体保护焊横焊接头无损检测方法研究.pdf
- CO2气保焊机与焊接工艺参数的匹配.pdf
- CO2气体保护焊焊接工艺试验与应用.pdf
- 基于智慧园区管理系统:基于园区业务,深度挖掘流程与系统的关键结合点,发挥互联网的优势,系统主要实现园区的资产管理,企业服务及档案管理,园区的活动及商城的搭建。全部资料+高分项目+详细文档.zip
- Cr25Ni20耐热不锈钢的焊接工艺 - .pdf
- 基于智慧园区 园区大脑-平台管理系统全部资料+高分项目+详细文档.zip
- CRHl型动车组构架焊接制造工艺分析 - .pdf
- CRH350横梁管和连接座选材与OTC机械手焊接工艺分析 - .pdf
- CR技术在超薄焊接结构件中的研究与应用.pdf
- CSA W47.1-1992 中文版 钢结构熔化焊的公司资格 焊接.pdf
- CT20低温钛合金氩弧焊接接头显微组织及性能 - .pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功