0
私のGui Appからユーザーのページを認証する必要があります。私はjavaとrestfbライブラリを使ってそれをどうやって解決するのか私にはわかりませんでした。私はGui Appからユーザーを認証することができますが、ユーザーの壁ではなくユーザーのページにアクセスしたいと思います。残り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を編集してページアクセストークンを取得する方法を教えてください。どうもありがとう。
全体のコード:このコードは、すべてのページ名とそのアクセストークンを出力します
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());
}
}
:
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;
}
}
}
この「コード」?それは唯一の文字列であり、何もしません。 – azro
このURL経由でページアクセストークンを取得しません。必要な権限を要求し、ユーザーのページのアクセストークンを取得するAPI要求を行う必要があります。ドキュメントは、それがどのように動作するかについて、実際にはかなり明確です。 – CBroe
もちろん、コードは何もしません。コードの唯一の部分ですが、最も重要な部分です。編集 –