kdb*_*lue 5 android google-signin
场景:
我想在我的Android应用程序中GOOGLE SIGN IN使用登录Firebase Google Login,我的基本需求是在我的应用程序中登录时检索USER性别USER.
问题:
即使我得到的性别USERS,但不是全部 USERS,那么,是因为越来越问题只是一些用户的性别是很奇怪的,所以我的问题是,为什么我没有得到所有用户的性别,同时登录?
public void performFirebaseLogin(GoogleSignInAccount acct, final Context context, final LoginSPrefRepositoryImpl loginSPrefRepositoryImpl) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
final GoogleAccountCredential googleCredential = GoogleAccountCredential.usingOAuth2(
context, Collections.singleton(Scopes.PROFILE));
mAuth.signInWithCredential(credential)
.addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
//here i am calling profile detail of user
new GetProfileDetails(user, googleCredential,loginSPrefRepositoryImpl).execute();
} else {
onLoginListener.onFailure("Login Failed");
}
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
}
}
});
}
//here i am retrieving user's information
class GetProfileDetails extends AsyncTask<Void, Void, Person> {
private PeopleService ps;
private int authError = -1;
private FirebaseUser user;
private LoginSPrefRepositoryImpl loginSPrefRepositoryImpl;
GetProfileDetails(FirebaseUser user, GoogleAccountCredential credential, LoginSPrefRepositoryImpl loginSPrefRepositoryImpl) {
this.loginSPrefRepositoryImpl = loginSPrefRepositoryImpl;
this.user = user;
credential.setSelectedAccount(
new Account(user.getEmail(), "com.google"));
HttpTransport HTTP_TRANSPORT = AndroidHttp.newCompatibleTransport();
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
ps = new PeopleService.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName("Google Sign In Quickstart")
.build();
}
@Override
protected Person doInBackground(Void... params) {
Person meProfile = null;
try {
meProfile = ps
.people()
.get("people/me")
.setPersonFields("genders")
.execute();
} catch (UserRecoverableAuthIOException e) {
e.printStackTrace();
authError = 0;
} catch (GoogleJsonResponseException e) {
e.printStackTrace();
authError = 1;
} catch (IOException e) {
e.printStackTrace();
authError = 2;
}
return meProfile;
}
@Override
protected void onPostExecute(Person meProfile) {
//mainAct.printBasic();
if (authError == 0) { //app has been revoke, re-authenticated required.
//mainAct.reqPerm();
} else if (authError == 1) {
Log.w(TAG, "People API might not enable at" +
" https://console.developers.google.com/apis/library/people.googleapis.com/?project=<project name>");
} else if (authError == 2) {
Log.w(TAG, "API io error");
} else {
if (meProfile != null) {
// Log.d("kkkk", "" + meProfile.getGenders());
JSONArray jsonArray = new JSONArray(meProfile.getGenders());
try {
JSONObject jsonObject = jsonArray.getJSONObject(0);
String gender = jsonObject.getString("formattedValue");
loginSPrefRepositoryImpl.isLoggedIn();
loginSPrefRepositoryImpl.setGender(gender);
onLoginListener.onSuccess(user);
} catch (JSONException e) {
e.printStackTrace();
onLoginListener.onFailure("Something went wrong !");
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是gender用户应该在他的Google +帐户上明确共享。我建议你自己尝试一下。
resourceName=people/me和personFields=gendersresourceName和etag字段的响应。TL;DR:G+ 上有Gender可见性设置,用户可能选择不分享他的性别,并且在身份验证期间没有专门的配置文件范围可供请求。此设置完全私密。
| 归档时间: |
|
| 查看次数: |
224 次 |
| 最近记录: |