2014-07-11 2 views
1

나는 작동 한 브라우저 컨트롤을 사용하여 클라이언트 측에서 페이스 북과 상호 작용하는 코드를 작성했습니다.자바 HTTP 요청 페이스 북에. 나쁜 요청

페이스 북 인증을 위해 서블릿 앱을 실행하려고합니다. 서블릿은 클라이언트에서 사용한 클래스를 다시 사용합니다.

url_conn의 값은 다음과 같습니다 https://graph.facebook.com/oauth/access_token?client_id= {내-ID 문자열} & client_secret = {영숫자 문자열 비밀} & fb_exchange_token = {정말 긴 영숫자 문자열} & grant_type = fb_exchange_token . {}이 (가) 사용 된 실제 값을 제거했습니다.

다음은 코드입니다. 뭐가 잘못 되었 니? 지침을 제공하십시오. 감사합니다

try{ 
     System.out.println("Attempting to open connection"); 
    conn = (HttpURLConnection) (url_conn.openConnection()); 
     if (conn.getResponseCode() != 200) { 
      System.out.println("Throwing IO Exception Successful on " + url_conn.toString()); 
     throw new IOException(conn.getResponseMessage()); 
     } 
    // conn.setRequestProperty("Accept-Charset","UTF-8"); 
     System.out.println("Attempt Successful"); 

     BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8")); 
     String json = reader.readLine(); 
     JsonReader MyJsonReader = Json.createReader(reader); 
     JsonObject jsonObject = MyJsonReader.readObject(); 

     MyJsonReader.close(); 
     reader.close();   

     sb = sb.append(jsonObject.toString());  
    } 
catch(Exception e) 
{ 
    System.out.println("Error From The FileCounter Class " + e.getMessage()); 
    e.printStackTrace(); 

} 

    conn.disconnect();  
    } 

답변

2

페이스 북은 https를 통해서만 액세스 할 수 있습니다 (s는 기본적으로 SSL/TLS상의 HTTP입니다). HttpURLConnection 클래스 (http://docs.oracle.com/javase/7/docs/api/javax/net/ssl/HttpsURLConnection.html) 대신 java의 HttpsURLConnection 클래스를 사용해보십시오. 예를 들면 다음과 같습니다. HttpsURLConnection con = (HttpsURLConnection)url.openConnection();

+0

THanks alot man. 또한 실수로 내 키를 잘라 냈습니다. 그것의 지금 고쳤다 –