access_token
이 유효한지 여부를 확인할 수 있습니다.
요청시 access_token을 사용하여 GET
요청을 API 끝점 인 https://www.googleapis.com/oauth2/v1/tokeninfo
에 보내야합니다.
이처럼 시도 할 수 있습니다 : 위의 코드에서 사용
String connection = new ConnectionService().connectionGoogle("https://www.googleapis.com/oauth2/v1/tokeninfo", "access_token=" + "YOUR_EXISTING_ACCESS_TOKEN");
System.out.println(connection);
방법 :
public static String connectionGoogle(String url, String parameter) throws MalformedURLException, ProtocolException, IOException {
URL url1 = new URL(url);
HttpURLConnection request1 = (HttpURLConnection) url1.openConnection();
request1.setRequestMethod("GET");
request1.setDoOutput(true);
request1.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStreamWriter wr = new OutputStreamWriter(request1.getOutputStream());
wr.write(parameter);
wr.flush();
request1.connect();
String responseBody = convertStreamToString(request1.getInputStream());
wr.close();
return responseBody;
}
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
} catch (IOException e) {
} finally {
try {
is.close();
} catch (IOException e) {
}
}
return sb.toString();
}
내가 질문에 대해 확실하지 않다. 앱이 Google 서버와 직접 통신하고 있기 때문에 개인 서버는 어디에 위치합니까? 안드로이드 앱 자체에서 토큰 유효성을 확인할 수 있습니다. 당신은 정교 할 수 있습니까? – drulabs
이미 클라이언트 앱 (안드로이드)에서 g +에서 액세스 토큰을 얻고 있습니다. 서버에 액세스 토큰을 보내고 있습니다. 해당 서버에서 Google로부터 해고당한 액세스 토큰의 유효성을 다시 확인하고 싶습니다. 사용자 정보 ... 해당 액세스 토큰을 사용 중입니다 .... 응답 해 주셔서 감사합니다 –
아무 작업이나 해보십시오. 토큰이 유효하면 검색이나 업로드 또는 기타와 마찬가지로 응답을 받거나 "승인되지 않은"응답을 받게됩니다. 일반적으로 토큰은 1 시간마다 또는 사용자가 명시 적으로 Google 비밀번호를 변경할 때 만료됩니다. 인증을 제대로 수행했다면 액세스 토큰으로 새로 고침 토큰을 받아야합니다. 이 새로 고침 토큰을 사용하여 새 액세스 토큰을 가져옵니다. – drulabs