ここで説明されている新しい Facebook エンドポイントを呼び出して、ユーザーの OAuth2.0 access_token を自動的に更新しようとしています。
私は Java (SEAM) Web アプリケーションを構築しています。Facebook の認証はサーバー側のフローを使用して行われます。
応答コード 400 が返され続けます。どこが間違っているのかわからないので、以下のコードに何か問題があると思いますか?
ありがとう
public static String refreshFBAccessToken(String existingAccessToken)
throws Exception{
try {
// Construct data
String data = URLEncoder.encode("client_id", "UTF-8") + "=" + URLEncoder.encode(FacebookApp.appId, "UTF-8");
data += "&" + URLEncoder.encode("client_secret", "UTF-8") + "=" + URLEncoder.encode(FacebookApp.appSecret, "UTF-8");
data += "&" + URLEncoder.encode("grant_type", "UTF-8") + "=" + URLEncoder.encode("fb_exchange_token", "UTF-8");
data += "&" + URLEncoder.encode("fb_exchange_token", "UTF-8") + "=" + URLEncoder.encode(existingAccessToken, "UTF-8");
// Send data
URL url = new URL("https://graph.facebook.com/oauth/access_token?");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(data);
writer.flush();
HttpURLConnection httpConn = (HttpURLConnection)connection;
InputStream is;
if (httpConn.getResponseCode() >= 400) {
is = httpConn.getInputStream();
System.err.println("Input Stream..."+is.toString());
} else {
is = httpConn.getErrorStream();
System.err.println("Error Stream..."+is.toString());
}
while((line = reader.readLine()) != null) {
System.err.println("Response: "+line);
builder.append(line);
}
return builder.toString();
} catch (Exception e) {
System.err.println(e);
}
return null;
}