Rest fb - 用于获取页面访问令牌的授权 URL



我需要从我的Gui应用程序验证用户的页面。我没有找到任何解决方案,如何使用java和restfb库来做到这一点。我能够从我的 Gui 应用程序对用户进行身份验证,但我想访问用户的页面,而不是用户的墙。

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;
}
}
}

这很简单:

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());
}
}

此代码将打印出所有页面名称及其访问令牌。您可以简单地将它们存储在字符串中,然后使用它们。

相关内容

最新更新