本文整理汇总了Java中facebook4j.auth.AccessToken类的典型用法代码示例。如果您正苦于以下问题:Java AccessToken类的具体用法?Java AccessToken怎么用?Java AccessToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessToken类属于facebook4j.auth包,在下文中一共展示了AccessToken类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRawFacebookExchangeToken
import facebook4j.auth.AccessToken; //导入依赖的package包/类
/**
*
* @return
* @throws FacebookException
* @throws JSONException
*/
private AccessToken getRawFacebookExchangeToken() throws FacebookException, JSONException{
String url = "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token";
String appId = configuration.getOAuthAppId();
String secret = configuration.getOAuthAppSecret();
String oldToken = configuration.getOAuthAccessToken();
url += "&client_id="+appId+
"&client_secret="+secret+
"&fb_exchange_token="+oldToken;
logger.info("entro a generar el nuevo token con el URL "+ url);
JSONObject json = getRawFacebookCall(url);
return new AccessToken(json.getString("access_token"), json.getLong("expires"));
}
示例2: FacebookFeed
import facebook4j.auth.AccessToken; //导入依赖的package包/类
public FacebookFeed(String searchTerm) {
//this.setConsumer("Put Consumer Key Here", "Put Consumer Secret Here");
//this.setToken("Put Token Here");
this.fbInstance = FacebookFactory.getSingleton();
fbInstance.setOAuthAppId(this.getConsumerKey(), this.getConsumerSecret());
fbInstance.setOAuthAccessToken(new AccessToken(this.getToken()));
try {
messages = fbInstance.searchPosts(searchTerm);
System.out.println(messages.size() + " messages retrieved.");
} catch (FacebookException ex) {
Logger.getLogger(FacebookFeed.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例3: getPages
import facebook4j.auth.AccessToken; //导入依赖的package包/类
/**
* Returns a list of all Facebook pages managed by the current user.
*
* @param req the http request
* @return list of all Facebook pages managed by the current user
* @throws IOException if an error occurred during access
*/
public static ResponseList<Account> getPages(HttpServletRequest req) throws IOException {
if (AuthHelper.isAuthenticated(req)) {
initFacebook(req);
try {
AccessToken at = Tokenmanager.getFacebookAccessToken(req);
facebook.setOAuthAccessToken(at);
return facebook.getAccounts();
} catch (FacebookException | IllegalStateException e) {
return null;
}
}
return null;
}
示例4: main
import facebook4j.auth.AccessToken; //导入依赖的package包/类
public static void main(String atgs[]) throws IOException, JSONException {
Facebook facebook = new FacebookFactory().getInstance();
facebook.setOAuthAppId(appId,appSecret);
facebook.setOAuthPermissions(permissions);
facebook.setOAuthAccessToken(new AccessToken(accessToken,1463769000L));
String keyword = "spallions";
Long fromTimestamp = 1463855400L; //22 may
Long toTimestamp = ((new Date()).getTime())/1000;
}
示例5: authorizeComplete
import facebook4j.auth.AccessToken; //导入依赖的package包/类
/**
* Authorise a new account to be accessible by Bot.
*/
public void authorizeComplete(String pin) throws FacebookException {
AccessToken token = this.connection.getOAuthAccessToken(pin);
setToken(token.getToken());
User user = this.connection.getMe();
this.userName = user.getId();
if (token.getExpires() != null) {
this.tokenExpiry = new Date(System.currentTimeMillis() + (token.getExpires() * 1000));
}
this.profileName = user.getName();
try {
this.page = "";
ResponseList<Account> accounts = this.connection.getAccounts();
this.pages = new ArrayList<String>();
if (accounts != null) {
for (Account account : accounts) {
this.page = account.getName();
this.pages.add(account.getName());
}
}
} catch (Exception exception) {
log(exception);
}
/* Map<String, String> params = new HashMap<String, String>();
params.put("client_id", this.oauthKey);
params.put("client_secret", this.oauthSecret);
params.put("grant_type", "fb_exchange_token");
params.put("fb_exchange_token", token.getToken());
RawAPIResponse apiResponse = this.connection.callGetAPI("/oauth/access_token", params);
String response = apiResponse.asString();
AccessToken newAccessToken = new AccessToken(response);
this.connection.setOAuthAccessToken(newAccessToken);
setToken(newAccessToken.getToken());
this.tokenExpiry = new Date(System.currentTimeMillis() + (newAccessToken.getExpires() * 1000));
System.out.println(this.tokenExpiry);*/
}
示例6: getRawFacebookExchangeToken
import facebook4j.auth.AccessToken; //导入依赖的package包/类
/**
*
* @return
* @throws FacebookException
* @throws JSONException
*/
private AccessToken getRawFacebookExchangeToken() throws FacebookException, JSONException{
String appId = configuration.getOAuthAppId();
String secret = configuration.getOAuthAppSecret();
String oldToken = configuration.getOAuthAccessToken();
String url = "https://graph.facebook.com/oauth/access_token?client_id="+appId+"&client_secret="+secret+"&grant_type=fb_exchange_token&fb_exchange_token="+oldToken;
logger.info("entro a generar el nuevo token con el URL "+ url);
JSONObject json = getRawFacebookCall(url);
return new AccessToken(json.getString("access_token"), json.getLong("expires"));
}
示例7: setFbVars
import facebook4j.auth.AccessToken; //导入依赖的package包/类
/**
* This method sets the facebook4j client and the user access token.
*
* @param fb preconfigured facebook4j client
* @param token Facebook user access token
*/
public static void setFbVars(Facebook fb, AccessToken token) {
FacebookStreamer.fb = fb;
FacebookStreamer.token = token;
}
示例8: setFbVars
import facebook4j.auth.AccessToken; //导入依赖的package包/类
/**
* This method sets the facebook4j client and the user access token.
*
* @param fb preconfigured facebook4j client
* @param token Facebook user access token
*/
public void setFbVars(Facebook fb, AccessToken token) {
FacebookStaticLoader.fb = fb;
FacebookStaticLoader.token = token;
}