2016-09-01 3 views
0

StoredCredential 파일을 저장하지 않고 처음으로 프로그램을 실행하면 프로그램이 브라우저를 열지 못합니다. 그런 다음 브라우저를 수동으로 열었을 때 인쇄 된 링크로 이동하여 내 계정에 대한 액세스를 허용하려면 정상적으로 누르십시오. 프로그램이 계속 실행되지 않습니다. 프로그램을 실행할 때마다 실제로이 작업을 수행합니다.gmail api에서 브라우저가 열리지 않습니다.

이 프로그램은 다음과 같이마다 (전용 링크 변경) 출력한다 : 내가 말했듯이, 지정된 링크가 자동으로 실행되지 않습니다

2016-08-31 22:15:53.250:INFO::Logging to STDERR via org.mortbay.log.StdErrLog 
2016-08-31 22:15:53.250:INFO::jetty-6.1.26 
2016-08-31 22:15:53.258:INFO::Started [email protected]:35268 
Please open the following address in your browser: 
    https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=723296789344-l7b6jp5ffkmeteokur8qmi5fd8rkont5.apps.googleusercontent.com&redirect_uri=http://localhost:35268/Callback&response_type=code&scope=https://www.googleapis.com/auth/gmail.labels%20https://www.googleapis.com/auth/gmail.compose%20https://www.googleapis.com/auth/gmail.modify 
Attempting to open that address in the default browser now... 

을 내가 수동으로 할 내 계정에 액세스를 허용 할 때 , 프로그램이 계속 실행되지 않습니다. 무슨 일이 일어날 지 모르는 어떤 아이디어? 또한 도움이된다면 우분투 16.04를 기본 브라우저가 올바르게 설정 한 상태로 사용하고 있습니다.

또한 OAuth 프레임 워크에서 계정 인증을 구현하기 시작하는 사람이 있습니까?

답변

0

나는이이 클래스 GoogleAuthorizationCodeFlow자격 증명 객체에 의해 처리됩니다 생각합니다. Java Quickstart for Gmail에서이 구현하는 방법을 볼 수 있습니다 여기에

public static Credential authorize() throws IOException { 
    // Load client secrets. 
    InputStream in = 
    GmailQuickstart.class.getResourceAsStream("/client_secret.json"); 
    GoogleClientSecrets clientSecrets = 
    GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in)); 

    // Build flow and trigger user authorization request. 
    GoogleAuthorizationCodeFlow flow = 
    new GoogleAuthorizationCodeFlow.Builder(
    HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) 
    .setDataStoreFactory(DATA_STORE_FACTORY) 
    .setAccessType("offline") 
    .build(); 
    Credential credential = new AuthorizationCodeInstalledApp(
    flow, new LocalServerReceiver()).authorize("user"); 
    System.out.println(
    "Credentials saved to " + DATA_STORE_DIR.getAbsolutePath()); 
    return credential; 
    } 

일부 주 Gmail에서 약 How authorization works입니다 :

1 : 높은 수준에서

, 모든 응용 프로그램은 동일한 기본 인증 패턴을 따른다 개발 중에는 Google API 콘솔에 애플리케이션을 등록하십시오.

2. 앱이 실행되면 사용자가 Google 계정의 데이터에 대한 액세스 권한을 부여하도록 요청합니다.

3. 사용자가 동의하면 응용 프로그램이 Gmail API에 액세스하기위한 자격 증명을 요청하고 수신합니다.

4. 자격 증명을 새로 고칩니다 (필요한 경우).

관련 문제