Firebase Android:Google登录失败

时间:2016-10-11 21:25:38

标签: android firebase firebase-authentication google-authentication

首先,我不得不说我对Android开发非常陌生,所以如果我忽略了一些明显的东西,请原谅我。

对于大学项目,我必须创建一个应用程序,首先使用Firebase通过其Google帐户对用户进行身份验证。我首先按照我发现here的说明进行操作。

首先,我复制粘贴this code from Firebase Tutorial.一切似乎都在起作用,除了一件事:

#!/bin/bash
function testFunction {
    local TESTPORT=$1
    expect << EOF
spawn sshpass -f x ssh -p ${TESTPORT} admin@localhost
expect "$ "
send -- "w\r"
expect "$ "
send "exit\r"
EOF
}
testFunction 8802
testFunction 8803

此处@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "------------------ onActivityResult ------------------"); super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); if (result.isSuccess()) { Log.d(TAG, "------------------ googleSignInSuccess ------------------"); // Google Sign In was successful, authenticate with Firebase GoogleSignInAccount account = result.getSignInAccount(); firebaseAuthWithGoogle(account); // Start menu activity once the user has been logged in Intent intent = new Intent(this, MenuActivity.class); startActivity(intent); } else { Log.d(TAG, "------------------ googleSignInFailure ------------------"); // Google Sign In failed, update UI appropriately // [START_EXCLUDE] //Log.d(TAG, result.getStatus().getStatusMessage()); updateUI(null); // [END_EXCLUDE] } } } 。所以我认为Google身份验证因某些原因无法理解而失败。我确信我输入了正确的密码,我还在我的应用的Firebase控制台中启用了Google帐户身份验证。

如果你能帮助我,请提前感谢你。

编辑:更准确地说,我第一次在模拟器上运行程序时(或每次我从中删除数据后),我必须在专用的Google中输入我的Google凭据弹出的登录活动。这工作正常,同样的活动似乎成功验证了我。但在此之后,result.isSuccess() == false仍然是假的,我不明白为什么。

3 个答案:

答案 0 :(得分:8)

我终于发现了问题,我在Firebase控制台here中验证我的应用时犯了一个错误(第34段&#34;开始之前#34;),第4步。我输入了<dom-module id="my-students-view"> <template> <style> :host { display: block; } </style> <!-- Iron-Ajax created connection and gets data --> <iron-ajax auto id="requestRepos" url="http://api.dev/user/" handle-as="json" loading="{{isloading}}" last-response="{{response}}"></iron-ajax> <!-- dom-repeat iterates the response --> <template is="dom-repeat" items="[[response.data]]" sort="sortData"> <student-card id="studentCard" to="http://localhost:8080/profile-view/{{item.id}}" picsrc="../../images/anonymous.jpg" name="{{item.first_name}} {{item.last_name}}" stdId="{{item.id}}" on-tap="sendId"></student-card> </template> </template> <script> Polymer({ is: 'my-students-view', properties: { stdId: { notify: true, } }, //Sort the array/data alphabetically sortData: function(a, b) { if(a.first_name < b.first_name) return -1; if(a.first_name > b.first_name) return 1; return 0; }, //Try to get the id value of a the student card sendId: function() { var idPropertie = this.$$("#studentCard"); var idValue = idPropertie.getAttribute('stdId'); console.log('the id is:' + idValue); }, }); </script> </dom-module> ,现在可以使用了。

尽管如此,谢谢!

答案 1 :(得分:2)

您可以使用import { Injectable } from '@angular/core'; import { Subject } from 'rxjs/Subject'; @Injectable() export class UiService { chapters: string; // Observable boolean streams navState$ = this.navStateSource.asObservable(); chapter = this._chapter.asObservable(); // Observable boolean sources private navStateSource = new Subject<boolean>(); private _chapter: Subject<number> = new Subject<number>(); // Service message commands changeNavState(showNav: boolean) { this.navStateSource.next(showNav); } changeChapter(chapter: number) { this._chapter.next(chapter); } } 检查结果的状态。记录此消息或调试结果Status,它应指出问题。 result.getStatus().getStatusMessage()还提供了Status方法,该方法提供了应该解决您的失败的待处理意图(首先检查解析是否可用于调用getResolution(),如果它可以处理它,则返回hasResolution()你)。

答案 2 :(得分:1)

尝试通过以下方式更改GSO:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();

希望这有帮助!