2012-11-27 2 views
3

나는이 사이트에서 처음 새롭게 왔습니다. 나는 내 문제에 대한 해답을 찾고 있었다. 그러나 나는이 웹 사이트에있는 누군가와 같은 문제를 보았다. 질문은 here 입니다. Windows 7을 사용하고 있습니다. 그 링크에서 대답을 얻지 못했습니다. 다시 같은 질문을하고 있습니다. 자바 애플리케이션에서 브라우저에 Gmail 계정 링크를 열고 싶습니다. 예, Desktop 클래스의 browse() 메소드에 대해 알고 있습니다. 문제는 내가 Gmail 웹 사이트를 열 수 있지만 사용자 이름과 비밀번호가 제공되는 동안 지정된 Gmail 계정을 직접 열어야한다는 것입니다. 어떤 아이디어?java : direct gmail url

+0

메일을 사용 하시겠습니까? 또는 다른 유사한 Google 드라이브? IMAP 또는 POP3를 사용하여 작업 할 수 있습니다. –

+4

나는 이것이 가능하지 않을 것이라고 확신한다. [이 링크에서] (http://www.marcofolio.net/tips/automatic_sign_into_gmail_using_a_bookmark.html) 아마 일하는 데 사용 된 설명이 있지만 나에게 적합하지 않습니다. 사용자가 자신의 Google 자격 증명을 제공하면 본질적으로 안전하지 않습니다. OAuth2를 사용하여 애플리케이션에서 직접 Google API를 사용할 수 있으므로 사용자에게는 Google 자격 증명이 제공되지 않습니다. – jlordo

답변

0

좋아요, 몇 가지주의해야 할 점이 있습니다 : 1. Google API를 사용한 마지막 시간은 이전 버전 이었기 때문에 지금은 상당히 다를 수 있습니다 2.이 코드는 테스트되지 않았습니다. 그냥 메모리에서 부분적으로 그리고 일부는 오래된 프로젝트에서 작성합니다. 의사 코드 (pseudo-code)와 좀 더 비슷하게 생각해보십시오. 3. 우연한 작업으로 해결하면 상당히 더러운 솔루션입니다. API를 사용하여 더 나은 방법을 찾을 수 있기를 바랍니다.

GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters(); 
oauthParameters.setOAuthConsumerKey([insert consumer key here]); 

oauthParameters.setOAuthConsumerSecret([insert consumer secret here]); 
OAuthSigner signer = new OAuthHmacSha1Signer(); 

GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer); 

oauthParameters.setScope("https://mail.google.com/mail"); //no clue if this is a valid scope or not 

oauthHelper.getUnauthorizedRequestToken(oauthParameters); 
String requestUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters); 

Desktop desktop = Desktop.getDesktop(); 
URI url; 
url = new URI(requestUrl); 
//this will make the user log in to authorize your app 
desktop.browse(url); 

//auth token response from Google, you can use this to authenticate your app if there are other requests you want to make against the user account 
String token = oauthHelper.getAccessToken(oauthParameters); 

//since you made sure the user is logged into their account to authorize your app, their gmail can now just be opened. Yes, very dirty. I know. (if it all works) 
desktop.browse("https://www.gmail.com/");