1

Google 드라이브의 API를 사용하여 독립 실행 형 Java 응용 프로그램을 개발하려고합니다 (Java SE 만 사용). 내가 상수 strings.My 질문에 내 자격 증명과 OAuth2.0에 URL을 넣어 가지고독립 실행 형 Java 응용 프로그램에서 Oauth2를 사용하여 액세스 토큰 가져 오기

package Drive; 

    import org.apache.http.HttpResponse; 
    import org.apache.http.client.HttpClient; 
    import org.apache.http.client.methods.HttpGet; 
    import org.apache.http.impl.client.DefaultHttpClient; 

    import java.io.BufferedReader; 
    import java.io.IOException; 
    import java.io.InputStreamReader; 

    import static Drive.Constants.*; 
    public class Test { 

     public static void main(String[] args) throws IOException { 

      String url=OAuth2URL+"redirect_uri=https://localhost/"+"&"+"client_id="+CLIENTID+"&"+"scope="+SCOPE+"&"+ 
        "access_type=offline&"+"response_type=code"; 

      System.out.println("URL is :"+url); 
      HttpClient httpClient= new DefaultHttpClient(); 
      HttpGet httpGet=new HttpGet(url); 
      HttpResponse response=httpClient.execute(httpGet); 
      if(response.getEntity().getContent()!=null) { 
       BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
       String str = null; 
       while ((str = reader.readLine()) != null) { 
        System.out.println(str); 
       } 
      } 

     } 
    } 

방법 입니다 : 그 동안 나는 Oauth2.0.For 코드 다음 내가 쓴 액세스 토큰을 받고 사용하여 액세스 토큰을 얻을 필요 내 API 호출의 응답을 내 애플리케이션으로 가져올 수 있습니까? 응답을 받으려면 특정 포트에서 청취 프로세스를 포크해야합니까?

답변

3

redirect_uri은 Google 콘솔에 (사용자가 client_id을 얻은 위치에) 등록해야하며이 URL을 실제 http/s 끝점으로 표시해야합니다.

자세한 내용은 2 단계 참조 : https://developers.google.com/identity/protocols/OAuth2InstalledApp

+0

안녕하세요 @ 도움 감사합니다. 하지만 oauth2 자격 증명 페이지에서 redirect_uri를 찾을 수 없습니다. –

+0

'웹 응용 프로그램'을 선택하고 '승인 된 리디렉션 URI'를 참조하십시오. https://console.cloud.google.com/apis/credentials/oauthclient –

관련 문제