0
我需要從我的Gui App中驗證用戶的頁面。我沒有找到任何解決方案,我怎麼用java和restfb庫來做到這一點。我能夠從我的Gui App驗證用戶,但我想訪問用戶的頁面,而不是用戶的牆。Rest fb - 授權url獲取頁面訪問令牌
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";
此代碼僅適用於用戶的牆/照片等等,但不適用於用戶的頁面。你能幫我怎麼編輯這個URL來獲取頁面訪問令牌嗎?非常感謝。
整個代碼:
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;
}
}
}
這個「code」?它只是字符串,它什麼都不做 – azro
您不會通過此URL獲得頁面訪問令牌。您需要請求必要的權限,然後發出API請求以獲取用戶頁面的訪問令牌。這些文件的工作原理非常清晰。 – CBroe
當然,這段代碼什麼都不做。它只是代碼的一部分,但卻是最關鍵的部分。請參閱編輯 –