本文整理匯總了Java中com.restfb.DefaultFacebookClient.fetchObject方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultFacebookClient.fetchObject方法的具體用法?Java DefaultFacebookClient.fetchObject怎麽用?Java DefaultFacebookClient.fetchObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.restfb.DefaultFacebookClient
的用法示例。
在下文中一共展示了DefaultFacebookClient.fetchObject方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import com.restfb.DefaultFacebookClient; //導入方法依賴的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);
}
}
示例2: launch
import com.restfb.DefaultFacebookClient; //導入方法依賴的package包/類
@Override
public boolean launch(String arguments) {
MY_ACCESS_TOKEN = arguments;
Runnable facebookProcessor = new Runnable() {
@Override
public void run() {
// Start by fetching the user's own posts first. Posts include statuses,
// links, photos, videos. Once the user's own posts are completely processed,
// the reporter will iteratively fetch posts for the user's friends.
client = new DefaultFacebookClient(MY_ACCESS_TOKEN);
User me = client.fetchObject("me", User.class);
String myId = me.getId();
Process myVertex = getUserVertex(myId);
processUserPhotos(myId);
processUserPosts(myId);
Connection<User> myFriends = client.fetchConnection("me/friends", User.class);
for (List<User> myFriend : myFriends) {
for (User friend : myFriend) {
String friendId = friend.getId();
Process friendVertex = getUserVertex(friendId);
WasTriggeredBy wtb = new WasTriggeredBy(friendVertex, myVertex);
putEdge(wtb);
processUserPosts(friendId);
processUserPhotos(friendId);
}
}
}
};
Thread facebookThread = new Thread(facebookProcessor, "Facebook-Thread");
facebookThread.start();
return true;
}
示例3: getTokenEmail
import com.restfb.DefaultFacebookClient; //導入方法依賴的package包/類
public String getTokenEmail(final ClientCredentials credentials, final String tokenString) {
if (credentials == null || isBlank(credentials.getId()) || isBlank(credentials.getSecret())) {
throw new IllegalArgumentException("Missing facebook credentials");
}
if (isBlank(tokenString)) {
throw new IllegalArgumentException("Invalid Facebook Token supplied.");
}
final DefaultFacebookClient client = new DefaultFacebookClient(tokenString, credentials.getSecret(), Version.VERSION_2_5);
final FacebookClient.DebugTokenInfo info = client.debugToken(tokenString);
if (info == null ||
!info.getAppId().equals(credentials.getId()) ||
!info.getExpiresAt().after(new Date())) {
throw new IllegalArgumentException("Invalid token");
}
if (info.getScopes() == null || info.getScopes().stream().noneMatch("email"::equalsIgnoreCase)) {
throw new IllegalArgumentException("Facebook 'email' scope is required");
}
final User user = client.fetchObject("me", User.class, Parameter.with("fields", "email,first_name,last_name"));
if (user == null || isBlank(user.getEmail())) {
throw new IllegalArgumentException("Token did not associate to a user with e-mail");
}
return user.getEmail();
}
示例4: postCode
import com.restfb.DefaultFacebookClient; //導入方法依賴的package包/類
@Override
public Response postCode(long customerId, int clientId, String code) {
if (!IdPool.clientInList(customerId, clientId)) {
clientNotFoundMsg.setCustomerId(customerId);
clientNotFoundMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(clientNotFoundMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
customer = FaceBookCustomerResource.getCustomerList().get(customerId);
client = customer.getClientDB().getClientList().get(clientId);
PostCodeMsg msg = new PostCodeMsg();
msg.setClientId(clientId);
msg.setCustomerId(customerId);
if (client.getStatus() == "on") {
msg.setLinkStatus(client.getStatus());
return Response.status(Response.Status.OK).entity(msg).type(MediaType.APPLICATION_JSON_TYPE).build();
} else {
try {
client.getLinkHandler().setToken(code);
fbClient = new DefaultFacebookClient(client.getLinkHandler().getToken());
user = fbClient.fetchObject("me", User.class);
client.setStatus(linkStatusOn);
msg.setLinkStatus(client.getStatus());
return Response.status(Response.Status.OK).entity(msg).type(MediaType.APPLICATION_JSON_TYPE).build();
} catch (Exception e) {
client.setStatus(linkStatusOff);
String errorMsg = "Link failed, Please verify your access token";
msg.setMessage(errorMsg);
return Response.status(Response.Status.OK).entity(msg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
}
}
示例5: getBasicProfile
import com.restfb.DefaultFacebookClient; //導入方法依賴的package包/類
@Override
public Response getBasicProfile(long customerId, int clientId) {
if (!IdPool.clientInList(customerId, clientId)) {
clientNotFoundMsg.setCustomerId(customerId);
clientNotFoundMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(clientNotFoundMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
customer = FaceBookCustomerResource.getCustomerList().get(customerId);
client = customer.getClientDB().getClientList().get(clientId);
if (client.getStatus() == linkStatusOff) {
notLinkedMsg = new NotLinked();
notLinkedMsg.setCustomerId(customerId);
notLinkedMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(notLinkedMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
fbClient = new DefaultFacebookClient(client.getLinkHandler().getToken());
user = fbClient.fetchObject("me", User.class);
client.getProfile().getBasicProfile().setId(user.getId());
client.getProfile().getBasicProfile().setName(user.getName());
client.getProfile().getBasicProfile().setWork(user.getWork());
return Response.status(Response.Status.OK).entity(client.getProfile().getBasicProfile()).type(MediaType.APPLICATION_JSON_TYPE).build();
}
示例6: getDetaiedProfile
import com.restfb.DefaultFacebookClient; //導入方法依賴的package包/類
@Override
public Response getDetaiedProfile(long customerId, int clientId) {
if (!IdPool.clientInList(customerId, clientId)) {
clientNotFoundMsg.setCustomerId(customerId);
clientNotFoundMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(clientNotFoundMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
customer = FaceBookCustomerResource.getCustomerList().get(customerId);
client = customer.getClientDB().getClientList().get(clientId);
if (client.getStatus() == linkStatusOff) {
notLinkedMsg = new NotLinked();
notLinkedMsg.setCustomerId(customerId);
notLinkedMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(notLinkedMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
fbClient = new DefaultFacebookClient(client.getLinkHandler().getToken());
user = fbClient.fetchObject("me", User.class);
client.getProfile().getBasicProfile().setId(user.getId());
client.getProfile().getBasicProfile().setName(user.getName());
client.getProfile().getBasicProfile().setWork(user.getWork());
client.getProfile().getDetailedProfile().setAbout(user.getAbout());
client.getProfile().getDetailedProfile().setBio(user.getBio());
client.getProfile().getDetailedProfile().setBirthday(user.getBirthday());
client.getProfile().getDetailedProfile().setEducations(user.getEducation());
client.getProfile().getDetailedProfile().setEmail(user.getEmail());
client.getProfile().getDetailedProfile().setGender(user.getGender());
client.getProfile().getDetailedProfile().setLocale(user.getLocale());
client.getProfile().getDetailedProfile().setPolitical(user.getPolitical());
client.getProfile().getDetailedProfile().setRelationshipStatus(user.getRelationshipStatus());
client.getProfile().getDetailedProfile().setReligion(user.getReligion());
client.getProfile().getDetailedProfile().setSports(user.getSports());
client.getProfile().getDetailedProfile().setWebsite(user.getWebsite());
return Response.status(Response.Status.OK).entity(client.getProfile()).type(MediaType.APPLICATION_JSON_TYPE).build();
}
示例7: PagePubTest01
import com.restfb.DefaultFacebookClient; //導入方法依賴的package包/類
public PagePubTest01() {
try {
fbClient = new DefaultFacebookClient(pageAccessToken, Version.LATEST);
myuser = fbClient.fetchObject("me", User.class);
mypage = fbClient.fetchObject(pageID, Page.class);
System.out.println(myuser);
System.out.println(mypage);
} catch (FacebookException ex) { //So that you can see what went wrong
ex.printStackTrace(System.err); //in case you did anything incorrectly
}
}
示例8: initUser
import com.restfb.DefaultFacebookClient; //導入方法依賴的package包/類
private static void initUser(String fbId, User user) {
String appId = Properties.get(FACEBOOK_APP_ID);
String appSecret = Properties.get(FACEBOOK_APP_SECRET);
AccessToken accessToken =
new DefaultFacebookClient().obtainAppAccessToken(appId, appSecret);
DefaultFacebookClient fbClient = new DefaultFacebookClient(accessToken.getAccessToken());
com.restfb.types.User fbUser = fbClient.fetchObject(fbId, com.restfb.types.User.class,
Parameter.with("fields", "id, first_name, last_name, email"));
user.setFirstName(fbUser.getFirstName());
user.setLastName(fbUser.getLastName());
if (fbUser.getEmail() != null) {
user.setRegisteredEmails(Lists.newArrayList(new RegisteredEmail(fbUser.getEmail(), true)));
}
}
示例9: Facebook
import com.restfb.DefaultFacebookClient; //導入方法依賴的package包/類
public Facebook() {
//read config
String line;
try (BufferedReader br = new BufferedReader( new FileReader(SelfPi.FACEBOOK_CONFIG_FILE_PATH) )){
line = br.readLine();
if (line != null && line.contains(FACETOKENKEY)) {
pageAccessToken = br.readLine();
}
line = br.readLine();
if (line != null && line.contains(FACEAPPIDKEY)) {
appID = br.readLine();
}
line = br.readLine();
if (line != null && line.contains(FACEPROFILEIDKEY)) {
pageID = br.readLine();
}
line = br.readLine();
if (line != null && line.contains(FACEUSERIDKEY)) {
userID = br.readLine();
}
line = br.readLine();
if (line != null && line.contains(FACEALBUMIDKEY)) {
albumID = br.readLine();
}
line = br.readLine();
if (line != null && line.contains(FACEPHOTOMSGIDKEY)) {
photoMsg = br.readLine();
}
} catch (IOException e) {
System.out.println("Error in config.txt");
};
try {
fbClient = new DefaultFacebookClient(pageAccessToken, Version.LATEST);
myuser = fbClient.fetchObject("me", User.class);
mypage = fbClient.fetchObject(pageID, Page.class);
System.out.println("Facebook initialized: USER: "+myuser+", PAGE: "+mypage);
} catch (FacebookException ex) { //So that you can see what went wrong
ex.printStackTrace(System.err); //in case you did anything incorrectly
}
}