Google API를 사용하기 시작한 순간 어둠 속에서 걷고있는 것처럼 느껴집니다.웹 사이트에서 Google 계정으로 로그인
그것은 매우 일반적인 기능입니다 :
은 내가 뭘 원하는지. 내 사이트에 javascipt를 사용하여 Google 계정 로그인 버튼이 있고 주어진 Gmail이 유효하고 계정에서 일부 기본 정보를 추출 할 수 있도록하고 싶습니다.
는 무엇을 내가 발견
https://developers.google.com/+/web/signin/javascript-flow : 여기에서 지침을 따랐다
.
그리고 지침의 마지막 단계에서 코드를 복사했습니다. '튜토리얼'의 지침을 따랐지만 내 버튼이 작동하지 않는 CLIENT_ID를 입력했습니다. 또한 몇 가지 예를 찾고 Google 사이트에서 찾은 코드와 많이 다릅니다. 나는 내가 뭔가를 놓치고 있다고 느낀다. (실제로 나는 내가 바보 같은 짓을한다고 생각한다.)).
그리고 여기에 내가 몇 가지 경고를 추가 한 내 코드
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta name="google-signin-clientid" content="'MY_CLIENT_ID'.apps.googleusercontent.com" />
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/plus.login" />
<meta name="google-signin-requestvisibleactions" content="http://schema.org/AddAction" />
<meta name="google-signin-cookiepolicy" content="single_host_origin" />
<script src="https://apis.google.com/js/client:platform.js" async defer></script>
<script type="text/javascript">
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
// Update the app to reflect a signed in user
// Hide the sign-in button now that the user is authorized, for example:
document.getElementById('signinButton').setAttribute('style', 'display: none');
} else {
// Update the app to reflect a signed out user
// Possible error values:
// "user_signed_out" - User is signed-out
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatically log in the user
console.log('Sign-in state: ' + authResult['error']);
}
}
function render() {
alert("1");
// Additional params including the callback, the rest of the params will
// come from the page-level configuration.
var additionalParams = {
'callback': signinCallback
};
alert("2");
// Attach a click listener to a button to trigger the flow.
var signinButton = document.getElementById('signinButton');
signinButton.addEventListener('click', function() {
gapi.auth.signIn(additionalParams); // Will use page level configuration
alert("3");
});
}
</script>
</head>
<body>
<button id="signinButton">Sign in with Google</button>
</body>
</html>
,하지만 아무것도 - 팝 없습니다까지 어디서나 '고객의 비밀'암호 나 자바 스크립트 기원을 사용하지 않았다. 또한 'MY_CLIENT_ID'대신 실제로 내 고객 ID입니다.
이것이 어떤 차이가 있는지는 잘 모르겠지만 내 사이트는 아직 서버에 없습니다. 그냥 로컬에서 일하는 것 (당연히 인터넷으로!)
내가 뭘 잘못했는지 알아?
불행하게도, 난 이미를했고, 나는 그것이 빈했다 .. – Mario