本文整理匯總了Java中com.restfb.DefaultFacebookClient類的典型用法代碼示例。如果您正苦於以下問題:Java DefaultFacebookClient類的具體用法?Java DefaultFacebookClient怎麽用?Java DefaultFacebookClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DefaultFacebookClient類屬於com.restfb包,在下文中一共展示了DefaultFacebookClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fetchFacebookUser
import com.restfb.DefaultFacebookClient; //導入依賴的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: SearchForTermUsingGeolocation
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
public void SearchForTermUsingGeolocation(String queryPar, int PageSize,
double latitude, double longitude, double radius) {
if (queryPar != null) {
facebookClient = new DefaultFacebookClient();
publicSearch = facebookClient.fetchConnection("search", Post.class,
Parameter.with("q", queryPar),
Parameter.with("type", "post"),
Parameter.with("limit", PageSize),
Parameter.with("place¢er", latitude + "," + longitude),
Parameter.with("distance", radius));
for (int i = 0; i < publicSearch.getData().size(); i++) {
if (publicSearch.getData().get(i).getMessage() != null) {
results.add(new FacebookPostData(publicSearch.getData()
.get(i)));
OldestDate = publicSearch.getData().get(i).getCreatedTime();
}
}
}
}
示例3: collectFeed
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
private Connection<Post> collectFeed(String pagename) {
AccessToken accessToken = new DefaultFacebookClient(Version.VERSION_2_3).obtainAppAccessToken(ConfigurationObject.MY_APP_ID, ConfigurationObject.MY_APP_SECRET);
FacebookClient facebookClient23 = new DefaultFacebookClient(accessToken.getAccessToken(), Version.VERSION_2_3);
//User user = facebookClient23.fetchObject("me", User.class);
Page page = facebookClient23.fetchObject(pagename, Page.class, Parameter.with("fields","name,id, picture, likes"));
return facebookClient23.fetchConnection(page.getId()+"/feed", Post.class, Parameter.with("fields", "comments, full_picture")); //message,picture, likes, from,
}
示例4: testDefaultAutoConfiguration
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
@Test
public void testDefaultAutoConfiguration() {
load(new Class[] {CallbackHandlerConfig.class, MessengerAutoConfiguration.class},
"restfbmessenger.verify-token: the_verify_token",
"restfbmessenger.access-token: the_access_token",
"restfbmessenger.app-secret: the_app_secret");
Messenger messenger = this.context.getBean(Messenger.class);
DefaultMessenger defaultMessenger = (DefaultMessenger) messenger;
FacebookClient facebookClient =
(FacebookClient) getFieldValue(defaultMessenger, "facebookClient");
DefaultFacebookClient defaultFacebookClient = (DefaultFacebookClient) facebookClient;
CallbackHandler callbackHandler =
(CallbackHandler) getFieldValue(defaultMessenger, "callbackHandler");
assertThat((String) getFieldValue(defaultMessenger, "verifyToken"), is("the_verify_token"));
assertThat((String) getFieldValue(defaultMessenger, "appSecret"), is("the_app_secret"));
assertThat((String) getFieldValue(defaultFacebookClient, "accessToken"),
is("the_access_token"));
assertThat((String) getFieldValue(defaultFacebookClient, "appSecret"),
is("the_app_secret"));
assertThat(callbackHandler, is(notNullValue()));
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings(),
hasItem("/webhook/*"));
}
示例5: testSerializer
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
@Before
public void testSerializer()
{
if (circles == 0)
{
if (!ConfLoader.confExists())
ConfLoader.genProperties();
String CURRENT_ACCESSTOKEN = ConfLoader.getProperties().getProperty(PropertyOption.ACCESS_TOKEN.toString());
maxPics = (long) -1;
try
{
maxPics = Long.parseLong(ConfLoader.getProperties().getProperty(PropertyOption.MAX_PHOTOS_PER_ALBUM.toString()));
} catch (NumberFormatException e)
{
}
skipAlbums = new ArrayList<>();
skipAlbums.addAll(Arrays.asList(ConfLoader.getProperties().getProperty(PropertyOption.SKIP_ALBUMS.toString()).split(";")));
fbc = new DefaultFacebookClient(CURRENT_ACCESSTOKEN, Version.VERSION_2_3);
facebook = new Facebook(fbc);
dir = new File(ConfLoader.getProperties().getProperty(PropertyOption.DIRECTORY.toString()));
}
circles++;
}
示例6: setNextPage
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
public void setNextPage() {
results = new ArrayList();
/*
* publicSearch = facebookClient.fetchConnectionPage(
* publicSearch.getNextPageUrl(), Post.class);
*/
facebookClient = new DefaultFacebookClient();
publicSearch = facebookClient.fetchConnectionPage(
publicSearch.getNextPageUrl(), Post.class);
for (int i = 0; i < publicSearch.getData().size(); i++) {
if (publicSearch.getData().get(i).getMessage() != null) {
results.add(new FacebookPostData(publicSearch.getData().get(i)));
}
}
}
示例7: setPreviousPage
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
public void setPreviousPage() {
results = new ArrayList();
/*
* publicSearch = facebookClient.fetchConnectionPage(
* publicSearch.getNextPageUrl(), Post.class);
*/
facebookClient = new DefaultFacebookClient();
publicSearch = facebookClient.fetchConnectionPage(
publicSearch.getPreviousPageUrl(), Post.class);
for (int i = 0; i < publicSearch.getData().size(); i++) {
if (publicSearch.getData().get(i).getMessage() != null) {
results.add(new FacebookPostData(publicSearch.getData().get(i)));
}
}
}
示例8: SearchForTerm
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
@Override
public void SearchForTerm(String queryPar, Integer PageSize) {
if (queryPar != null) {
results = new ArrayList();
facebookClient = new DefaultFacebookClient();
publicSearch = facebookClient.fetchConnection("search", Post.class,
Parameter.with("q", queryPar),
Parameter.with("type", "post"),
Parameter.with("limit", PageSize));
for (int i = 0; i < publicSearch.getData().size(); i++) {
if (publicSearch.getData().get(i).getMessage() != null) {
results.add(new FacebookPostData(publicSearch.getData()
.get(i)));
}
}
}
}
示例9: SearchFacebookPages
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
public void SearchFacebookPages(String queryPar, Integer PageSize) {
Connection<Page> publicSearch;
if (queryPar != null) {
resultPages = new ArrayList();
facebookClient = new DefaultFacebookClient();
publicSearch = facebookClient.fetchConnection("search", Page.class,
Parameter.with("q", queryPar),
Parameter.with("type", "page"),
Parameter.with("limit", PageSize));
for (int i = 0; i < publicSearch.getData().size(); i++) {
if (publicSearch.getData().get(i).getName() != null) {
resultPages.add(new FacebookPageData(publicSearch.getData()
.get(i)));
}
}
}
}
示例10: getUserFromFacebookUid
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
private LoginResult getUserFromFacebookUid(String token) {
LoginResult loginResult = null;
FacebookClient client = new DefaultFacebookClient(token);
com.restfb.types.User user = client.fetchObject("me", com.restfb.types.User.class);
String uid = user.getId();
try {
loginResult = db.getLoginInformationUsingNetworkId(FACEBOOK_NAME, uid);
} catch (SQLException e) {
logger.Error(e);
return null;
}
String sid = SessionManager.get().createSession(loginResult);
loginResult.setSid(sid);
if(loginResult.isSuccess() && (loginResult.isAdmin() || !loginResult.isDeleted())) {
logger.Info("Login user #" + loginResult.getUid() + ": " + loginResult.getUsername() + " (Using Facebook ID #" +uid + " in Web-Application)");
}
return loginResult;
}
示例11: getExtendedAccessToken
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
/**
* Exchange the short lived token (2h) for a long lived one (60j).
*
* @param accessToken Short lived token
* @return Long lived token
* @throws AuthenticationException Invalid token
*/
public String getExtendedAccessToken(String accessToken) throws AuthenticationException {
FacebookClient facebookClient = new DefaultFacebookClient(accessToken);
AccessToken extendedAccessToken = null;
try {
extendedAccessToken = facebookClient.obtainExtendedAccessToken(facebookAppId, facebookAppSecret, accessToken);
if (log.isDebugEnabled()) {
log.debug(MessageFormat.format("Got long lived session token {0} for token {1}", extendedAccessToken, accessToken));
}
} catch (FacebookException e) {
if (e.getMessage().contains("Error validating access token")) {
throw new AuthenticationException("Error validating access token");
}
throw new RuntimeException("Error exchanging short lived token for long lived token", e);
}
return extendedAccessToken.getAccessToken();
}
示例12: post
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
@Override
public String post(FacebookPosting posting) {
try {
FacebookClient facebookClient = new DefaultFacebookClient(ACCESS_TOKEN);
FacebookType publishMessageResponse = facebookClient.publish(FACEBOOK_PAGE + "/links", FacebookType.class,
Parameter.with("message", posting.getMessage()),
Parameter.with("link", posting.getLink()),
Parameter.with("og:name", posting.getName()),
Parameter.with("description", posting.getDescription()),
Parameter.with("icon", posting.getPicture()),
Parameter.with("picture", posting.getPicture())
);
String facebookUrl = "http://www.facebook.com/permalink.php?story_fbid=" + publishMessageResponse.getId() + "&id=" + FACEBOOK_PAGE;
log.info("Successfully posted [" + posting.getMessage() + "] to Facebook at [" + facebookUrl + "].");
return facebookUrl;
} catch (RuntimeException e) {
log.warning("Failed to post [" + posting.getMessage() + "] to Facebook.");
log.throwing(getClass().getName(), "post", e);
throw e;
}
}
示例13: 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);
}
}
示例14: createUser
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
@Override
public UserInfo createUser(CredentialVerificationResult verificationResult) {
FacebookCredentialVerificationCtx ctx =
(FacebookCredentialVerificationCtx) verificationResult.getVerificationCtx();
DefaultFacebookClient fbClient = new DefaultFacebookClient(ctx.getAuthToken());
// Getting age_range unfortunately requires explicitly specifiying the fields.
ExtFbUser fbUser = fetchObject(fbClient, "me", ExtFbUser.class,
Parameter.with("fields", "id, first_name, last_name, email, location, age_range, gender"));
User user = User.create();
user.setFirstName(fbUser.getFirstName());
user.setLastName(fbUser.getLastName());
if (fbUser.getEmail() != null) {
user.getRegisteredEmails().add(new RegisteredEmail(fbUser.getEmail(), true));
}
user.setAddress(parseCity(fbUser));
user.setGender(parseGender(fbUser));
user.setAgeRange(parseAgeRange(fbUser));
return new UserInfo(user,
new UserInfo.ProfileImage(
ImageProviderType.FACEBOOK,
getProfileImageUrl(fbUser.getId())) );
}
示例15: initOrganization
import com.restfb.DefaultFacebookClient; //導入依賴的package包/類
@Override
public void initOrganization(Organization org, String fbPageName) {
DefaultFacebookClient fbClient = new DefaultFacebookClient(getAppCredentials().getToken());
// Getting age_range unfortunately requires explicitly specifiying the fields.
Page fbPage = fetchObject(fbClient, fbPageName, Page.class);
// Relying on fb page name uniqueness
org.setName(Organization.orgIdToName(fbPageName));
org.setOrgName(fbPage.getName());
org.setPage(PageRef.create(fbPageName, PAGE_BASE_URL + fbPageName,
SocialNetworkProviderType.FACEBOOK));
String mission = null;
if (fbPage.getMission() != null) {
mission = fbPage.getMission();
} else if (fbPage.getAbout() != null) {
mission = fbPage.getAbout();
}
org.setMission(mission);
org.setAddress(getAddress(fbPage.getLocation()));
}