[英]Google APIs Issue
我正在嘗試從我的網站實現“使用 google 登錄”按鈕。
我嘗試了 javascript:
<script>
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: 'MY_CLIENT_ID.apps.googleusercontent.com',
fetch_basic_profile: false,
scope: "email" //I do only need the email for the moment
});
auth2.signIn().then(function() {
console.log(auth2.currentUser.get().getId());
});
});
</script>
和“非javascript”:
<meta name="google-signin-scope" content="email">
<meta name="google-signin-client_id" content="MY_CLIENT_ID.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
function google(googleUser) {
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
}
function fail(error) {
console.log(error);
}
</script>
<div class="g-signin2" data-onsuccess="google" data-onfailure="fail" data-theme="dark" data-longtitle="true"></div>
版本。
但是在這兩種情況下,我都會收到此錯誤(作為第一個腳本中的錯誤,以及第二個腳本中來自 fail() 的日志):
TypeError: this.u3.open is not a function
at fv.open (cb=gapi.loaded_0:250)
at gw (cb=gapi.loaded_0:298)
at Dx (cb=gapi.loaded_0:341)
at $w (cb=gapi.loaded_0:337)
at xx.<anonymous> (cb=gapi.loaded_0:338)
at new _.rk (cb=gapi.loaded_0:188)
at xx.Ej (cb=gapi.loaded_0:338)
at bx.a.<computed> [as signIn] (cb=gapi.loaded_0:321)
at login:269
at platform.js:28
我已經在 API 開發人員控制台中將我的域列入白名單......我做錯了什么?
通過添加ux_mode: "redirect"
到初始化器/元標記來解決
它變成了這樣:
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: 'MY_CLIENT_ID.apps.googleusercontent.com',
fetch_basic_profile: false,
scope: "email",
ux_mode: "redirect"
});
auth2.signIn().then(function() {
console.log(auth2.currentUser.get().getId());
});
});
問題是現在我不能調用fail()
的success()
) 。
我知道這是題外話,但在評論或這里的任何幫助將不勝感激!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.