Chúng tôi có một ứng dụng dựa trên Google để xác thực người dùng của mình đối với tài khoản ứng dụng google của chúng tôi và sau đó thực hiện một số xác minh và tra cứu nhóm trên máy chủ.API Google+ không trả về access_token Javascript
Gần đây, google đã thay đổi tên của đối tượng đã giữ biến access_token mà chúng tôi yêu cầu để xác thực. Trong các tài liệu (https://developers.google.com/identity/sign-in/web/reference#googleusergetbasicprofile) nó nói rằng access_token có sẵn từ phương thức getAuthResponse(), tuy nhiên khi tôi sử dụng nó trở lại là không xác định. Kiểm tra đối tượng sau console.log() cho thấy tất cả các trường khác được đề cập ngoại trừ access_token. Tôi lo lắng rằng Google sẽ thay đổi đối tượng một lần nữa trong tương lai và để lại cho chúng tôi mà không có ứng dụng của chúng tôi. Đây là mã.
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<meta name="google-signin-client_id" content="XXX.apps.googleusercontent.com">
<script>
//This happens after the user has authenticated with Google and has been passed
//back to the page
function onSignIn(googleUser) {
//Check to see whether the user is trying to sign out.
if (window.location.href.indexOf("signOut=1") !== -1) {
//Sign them out of the application.
signOut();
//redirect them to the same page, without the signOut query string so they can log back in if want
window.location.href='googlesigninform.html'
return false;
}
//Grab the token, access token and email.
var _id = googleUser.getAuthResponse().id_token; //This works
var _accessToken = googleUser.Ka.access_token; //This works but changed from googleUser.B.access_token
var profile = googleUser.getBasicProfile(); //Works
console.log(googleUser.access_token); //Undefined
console.log(googleUser.getAuthResponse().access_token);//Undefined
//Make a post request to the API
makePostRequest(_id, _accessToken, profile.getEmail());
}
Cách chính xác để truy cập biến access_token là gì?
Đây có phải là ngu ngốc của một câu hỏi mà không ai trả lời? –
Xảy ra một lần nữa đêm qua. Các đối tượng thô một lần nữa thay đổi tên và phá vỡ các ứng dụng của chúng tôi. –