本文整理汇总了Java中com.restfb.types.User类的典型用法代码示例。如果您正苦于以下问题:Java User类的具体用法?Java User怎么用?Java User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
User类属于com.restfb.types包,在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchFacebookUser
import com.restfb.types.User; //导入依赖的package包/类
private AuthUser fetchFacebookUser(String accessToken)
{
//TODO: this takes too long, maybe cache the access token for a configurable time
FacebookClient client = new DefaultFacebookClient(accessToken, Version.VERSION_2_5);
try
{
User user = client.fetchObject("me", User.class, Parameter.with("fields", "name,email"));
if (user != null)
{
AuthUser authUser = new AuthUser();
authUser.setName(user.getName());
authUser.setEmail(user.getEmail());
authUser.setAuthVendor(AuthVendor.FACEBOOK);
authUser.setSession(accessToken);
return authUser;
}
}
catch (FacebookException ex)
{
}
return null;
}
示例2: printUserInfo
import com.restfb.types.User; //导入依赖的package包/类
private void printUserInfo(User user){
if (user == null) {
System.err.println("AjaxController: No user.");
return;
}
StringBuilder info = new StringBuilder();
String splitter = ":\t";
info.append("Name").append(splitter).append(user.getName()).append("\n");
if (user.getHometown() != null) {
info.append("HomeTown").append(splitter).append(user.getHometown().getName()).append("\n");
}
if (user.getLocation() != null) {
info.append("Location").append(splitter).append(user.getLocation().getName()).append("\n");
}
info.append("Work").append(splitter).append(user.getWork()).append("\n");
info.append("Likes").append(splitter).append(user.getLikes()).append("\n");
System.out.print(info.toString());
}
示例3: fetchObjectsAsJsonObject
import com.restfb.types.User; //导入依赖的package包/类
void fetchObjectsAsJsonObject() {
out.println("* Fetching multiple objects at once as a JsonObject *");
List<String> ids = new ArrayList<String>();
ids.add("4");
ids.add("http://www.imdb.com/title/tt0117500/");
// Make the API call
JsonObject results = facebookClient25.fetchObjects(ids, JsonObject.class);
System.out.println(results.toString());
// Pull out JSON data by key and map each type by hand.
JsonMapper jsonMapper = new DefaultJsonMapper();
User user = jsonMapper.toJavaObject(results.getString("4","{}"), User.class);
Url url = jsonMapper.toJavaObject(results.get("http://www.imdb.com/title/tt0117500/").toString(), Url.class);
out.println("User is " + user);
out.println("URL is " + url);
}
示例4: testGetUserProfile
import com.restfb.types.User; //导入依赖的package包/类
@Test
public void testGetUserProfile() {
String userId = "user id";
User user = new User();
user.setFirstName("first name");
user.setLastName("last name");
ProfilePictureSource picture = new ProfilePictureSource();
picture.setUrl("url");
user.setPicture(picture);
user.setLocale("locale");
user.setTimezone(1.00);
user.setGender("gender");
when(facebookClient.fetchObject(userId, User.class, Parameter.with(USER_FIELDS_PARAM_NAME, USER_FIELDS_DEFAULT_VALUE)))
.thenReturn(user);
assertThat(messenger.getUserProfile(userId), is(user));
}
示例5: getUserVertex
import com.restfb.types.User; //导入依赖的package包/类
public Process getUserVertex(String userId) {
// A user vertex is created from the userId and cached for later reference
// to prevent repetitive REST calls.
if(userId == null){
logger.log(Level.WARNING, "a null value was recived as userId, this is probably because of a deleted facebook account");
return null;
}else if (objects.containsKey(userId)) {
return (Process) objects.get(userId);
}
User user=null;
try{
user = client.fetchObject(userId, User.class);
Process process = new Process();
process.addAnnotation("userId", user.getId());
process.addAnnotation("name", user.getName());
objects.put(userId, process);
putVertex(process);
return process;
}catch(Exception e){
logger.log(Level.WARNING, "userID = "+userId+" a graph request failed in getUserVertex, probably because of a deleted facebook account or a bad request");
}
return null;
}
示例6: processLikes
import com.restfb.types.User; //导入依赖的package包/类
public void processLikes(String objectId) {
// Likes are processed for each object (post or comment). A like is represented
// by an edge from the user to the object.
Connection<User> userPages = client.fetchConnection(objectId + "/likes", User.class);
for (List<User> users : userPages) {
for (User user : users) {
Process userProcess = getUserVertex(user.getId());
if(userProcess == null){
continue;
}
Artifact post = (Artifact) objects.get(objectId);
WasGeneratedBy wgb = new WasGeneratedBy(post, userProcess);
wgb.addAnnotation("fbType", "like");
putEdge(wgb);
}
}
}
示例7: fetchObjectsAsJsonObject
import com.restfb.types.User; //导入依赖的package包/类
void fetchObjectsAsJsonObject() {
out.println("* Fetching multiple objects at once as a JsonObject *");
List<String> ids = new ArrayList<String>();
ids.add("btaylor");
ids.add("http://www.imdb.com/title/tt0117500/");
// Make the API call
JsonObject results = facebookClient.fetchObjects(ids, JsonObject.class);
// Pull out JSON data by key and map each type by hand.
JsonMapper jsonMapper = new DefaultJsonMapper();
User user = jsonMapper.toJavaObject(results.getString("btaylor"), User.class);
Url url = jsonMapper.toJavaObject(results.getString("http://www.imdb.com/title/tt0117500/"), Url.class);
out.println("User is " + user);
out.println("URL is " + url);
}
示例8: search
import com.restfb.types.User; //导入依赖的package包/类
void search() {
out.println("* Searching connections *");
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"));
if (publicSearch.getData().size() > 0)
out.println("Public search: " + publicSearch.getData().get(0).getMessage());
out.println("Posts on my wall by friends named Mark: " + targetedSearch.getData().size());
}
示例9: oauthExceptionWithErrorSubcode
import com.restfb.types.User; //导入依赖的package包/类
/**
* Do we correctly handle the case where FB returns an OAuthException with an error code and subcode?
*/
@Test
public void oauthExceptionWithErrorSubcode() {
FacebookClient facebookClient =
facebookClientWithResponse(new Response(403,
"{\"error\":{\"message\":\"App Not Installed\",\"type\":\"OAuthException\",\"code\":190,\"error_subcode\":458}}"));
try {
facebookClient.fetchObject("me", User.class);
} catch (FacebookOAuthException e) {
assertEquals("App Not Installed", e.getErrorMessage());
assertEquals("OAuthException", e.getErrorType());
assertEquals(Integer.valueOf(190), e.getErrorCode());
assertEquals(Integer.valueOf(458), e.getErrorSubcode());
}
}
示例10: testMultipleFieldsWithSameName
import com.restfb.types.User; //导入依赖的package包/类
@Test
public void testMultipleFieldsWithSameName() {
JsonMapper jsonMapper = createJsonMapper();
User user1 = jsonMapper.toJavaObject(jsonFromClasspath("user-with-hometown-v1"), User.class);
assertTrue("Beograd".equals(user1.getHometownName()));
assertTrue(user1.getHometown() == null);
User user2 = jsonMapper.toJavaObject(jsonFromClasspath("user-with-hometown-v2"), User.class);
assertTrue("Belgrade, Serbia".equals(user2.getHometown().getName()));
assertTrue("Belgrade, Serbia".equals(user2.getHometownName()));
Post post1 = jsonMapper.toJavaObject(jsonFromClasspath("post-with-likes-v1"), Post.class);
assertTrue(post1.getLikesCount() == 4);
assertTrue(post1.getLikes() == null);
Post post2 = jsonMapper.toJavaObject(jsonFromClasspath("post-with-likes-v2"), Post.class);
assertTrue(post2.getLikes().getCount() == 49);
assertTrue(post2.getLikesCount() == 49);
}
示例11: run
import com.restfb.types.User; //导入依赖的package包/类
/**
* Bezieht die Informationen eines Profils von Facebook
*/
@Override
public void run() {
apiConnection = new DefaultFacebookClient(this.token);
auser = apiConnection.fetchObject(user, User.class);
FacebookProfile fbp = new FacebookProfile(auser.getUsername(), auser.getId());
fbp.setName(auser.getFirstName(), auser.getLastName());
fbp.setLink(auser.getLink());
fbp.setLocales(auser.getLocale());
queue.add(fbp);
if (FacePath.DEBUG >= 4){
System.out.println("GUFAPI-created: "+user);
}
}
示例12: getMyFriends
import com.restfb.types.User; //导入依赖的package包/类
@Deprecated
public List<FacebookProfile> getMyFriends() {
Connection<User> myFriends = apiConnection.fetchConnection("me/friends", User.class);
List<User> friendsList = myFriends.getData();
List<String> todo = new ArrayList<String>();
List<FacebookProfile> result = new ArrayList<FacebookProfile>();
for (User friend : friendsList) {
todo.add(friend.getId());
}
Collection<FacebookProfile> value = this.getUserFromThreadedAPI(todo);
for (FacebookProfile val : value) {
result.add(val);
}
return result;
}
示例13: testJsonParser
import com.restfb.types.User; //导入依赖的package包/类
@Test
public void testJsonParser() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
AjaxController controller = new AjaxController();
Method parseUserDataMethod = controller.getClass().getDeclaredMethod("parseUserData", String.class);
parseUserDataMethod.setAccessible(true);
String testJson = "{\"name\":\"Zlatan Popovic\",\"id\":\"7777777777777777\"}";
User user = (User) parseUserDataMethod.invoke(controller, testJson);
assertEquals("Zlatan Popovic", user.getName());
assertEquals("7777777777777777", user.getId());
}
示例14: fetchObject
import com.restfb.types.User; //导入依赖的package包/类
void fetchObject() {
out.println("* Fetching single objects *");
User user = facebookClient25.fetchObject("me", User.class);
Page page = facebookClient25.fetchObject("cocacola", Page.class);
out.println("User name: " + user.getName());
out.println("Page likes: " + page.getLikes());
}
示例15: fetchConnections
import com.restfb.types.User; //导入依赖的package包/类
void fetchConnections() {
out.println("* Fetching connections *");
Connection<User> myFriends = facebookClient25.fetchConnection("me/friends", User.class);
Connection<Post> myFeed = facebookClient25.fetchConnection("me/feed", Post.class);
out.println("Count of my friends: " + myFriends.getData().size());
if (!myFeed.getData().isEmpty())
out.println("First item in my feed: " + myFeed.getData().get(0).getMessage());
}