我需要从我的Gui App验证用户的页面。我没有找到任何解决方案,如何使用java和restfb库。我可以从我的Gui App验证用户,但我想访问用户的页面,而不是用户的墙。
String domain = "http://seznam.cz/";
String appId = "1784741508503328";
String authUrl = "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id="+appId+"&redirect_uri="+domain+"&scope=user_about_me,"
+ "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_birthday,user_education_history,"
+ "user_events,user_photos,user_friends,user_games_activity,user_hometown,user_likes,user_location,user_photos,user_relationship_details,"
+ "user_relationships,user_religion_politics,user_status,user_tagged_places,user_videos,user_website,user_work_history,ads_management,ads_read,email,"
+ "manage_pages,publish_actions,read_insights,user_friends,read_page_mailboxes,rsvp_event";
此代码仅适用于用户的墙/照片......等但不适用于用户的页面。你可以帮我修改一下这个网址来获取页面访问令牌吗?非常感谢。
整个代码:
public void getAccessToken(){
String domain = "http://seznam.cz/";
String appId = "1784741508503328";
String authUrl = "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id="+appId+"&redirect_uri="+domain+"&scope=user_about_me,"
+ "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_birthday,user_education_history,"
+ "user_events,user_photos,user_friends,user_games_activity,user_hometown,user_likes,user_location,user_photos,user_relationship_details,"
+ "user_relationships,user_religion_politics,user_status,user_tagged_places,user_videos,user_website,user_work_history,ads_management,ads_read,email,"
+ "manage_pages,publish_actions,read_insights,user_friends,read_page_mailboxes,rsvp_event";
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get(authUrl);
while(true){
if(!driver.getCurrentUrl().contains("facebook.com")){
String url = driver.getCurrentUrl();
accessToken = url.replaceAll(".*#access_token=(.+)&.*", "$1");
PrintWriter p = null;
try {p = new PrintWriter("users.txt");}
catch (FileNotFoundException ex) {Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);}
fbClient = new DefaultFacebookClient(accessToken);
if(!accessToken.equals("null")){
p.println(extendToken().getAccessToken() + "," + extendToken().getExpires());
}
else{
p.print("");
}
driver.quit();
p.close();
return;
}
}
}
答案 0 :(得分:-1)
很简单:
Connection<Account> result2 = fbClient.fetchConnection("me/accounts",Account.class);
for(List<Account> page : result2){
for(Account a : page){
System.out.println(a.getAccessToken());
System.out.println(a.getName());
}
}
此代码将打印出所有页面名称及其访问权限。您可以将它们存储在String中,然后再使用它们。