Java meProfile=service.people().get(“people/me”).execute();总是返回null

Java meProfile=service.people().get(“people/me”).execute();总是返回null,java,android,null,google-people,Java,Android,Null,Google People,我正在尝试使用Google people API来获取个人用户信息,如出生日期、年龄范围、兴趣等 但是当我尝试使用下面的代码访问它时 meProfile = service.people().get("people/me").setRequestMaskIncludeField("people.AgeRange").execute(); 代码返回null。 我的“meProfile”对象始终为空。 我甚至试过设置旗帜 像 即使在那时,结果也是一样的。我得到的是空值 我的LoginActivit

我正在尝试使用Google people API来获取个人用户信息,如出生日期、年龄范围、兴趣等

但是当我尝试使用下面的代码访问它时

meProfile = service.people().get("people/me").setRequestMaskIncludeField("people.AgeRange").execute();
代码返回null。 我的“meProfile”对象始终为空。 我甚至试过设置旗帜 像

即使在那时,结果也是一样的。我得到的是空值

我的LoginActivity的完整代码如下所示

LOGINACTIVITY.java

import android.accounts.Account;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.Scopes;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.people.v1.People;
import com.google.api.services.people.v1.model.Gender;
import com.google.api.services.people.v1.model.Person;
import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class LoginActivity extends AppCompatActivity implements
        View.OnClickListener,
        GoogleApiClient.OnConnectionFailedListener
{
    private static HttpTransport HTTP_TRANSPORT;
    private static JsonFactory JSON_FACTORY;
private static final String TAG = "GoogleActivity";
private static final int RC_SIGN_IN = 9001;
private String email,name,fname;

private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;


private GoogleApiClient mGoogleApiClient;
Button signUpBtn,loginFireBaseBtn,loginGoogleBtn;
EditText loginEt,passwordEt;
private ProgressDialog progressDialog;


@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    mAuth = FirebaseAuth.getInstance();
    loginEt=(EditText)findViewById(R.id.emailLoginEt);
    passwordEt=(EditText)findViewById(R.id.passwordLoginEt);
    loginFireBaseBtn=(Button)findViewById(R.id.loginBtn);
    signUpBtn= (Button)findViewById(R.id.signUpBtn);

    findViewById(R.id.googleSignInButton).setOnClickListener(this);
    loginFireBaseBtn.setOnClickListener(this);
    signUpBtn.setOnClickListener(this);

    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null)
            {
                // User is signed in
                if (name!=null&&email!=null&&fname!=null)
                {
                    Toast.makeText(getApplicationContext(),"GOOGLE: \n"+email+"\n"+name+"\n"+fname, Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(getApplicationContext(), NonAdminACtivity.class);
                    overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
                    startActivity(intent);
                    finish();
                }
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            }
            else
            {
                // User is signed out
                Toast.makeText(getApplicationContext(),"Signed out", Toast.LENGTH_LONG).show();
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
        }
    };

    // [START config_signin]
    // Configure Google Sign In
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    // [END config_signin]

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

}

@Override
public void onStart() {
    super.onStart();
    mAuth.addAuthStateListener(mAuthListener);
}
@Override
public void onStop() {
    super.onStop();
    if (mAuthListener != null) {
        mAuth.removeAuthStateListener(mAuthListener);
    }
}

public void showProgressBar()
{
    progressDialog = new ProgressDialog(LoginActivity.this,
            R.style.MyTheme);
    progressDialog.setCancelable(false);
    progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
    progressDialog.setMessage("Haha Can't Hack...");
    progressDialog.show();

}


public void cancelProgressBar()
{
    progressDialog.dismiss();

}

@Override
public void onClick(View v)
{
   if (v.getId()==R.id.loginBtn)
   {
        firebaseLogin();
   }
   if (v.getId()==R.id.googleSignInButton)
   {
        googleLogin();
   }
   if (v.getId()==R.id.signUpBtn)
   {
       firebaseSignUp();
   }
}

private void googleLogin()
{
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    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()) {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.getSignInAccount();
            email = account.getEmail();
            name = account.getDisplayName();
            fname = account.getFamilyName();

            getPersonalInfo(account);

            firebaseAuthWithGoogle(account);

        } else {
            // Google Sign In failed, update UI appropriately
            // [START_EXCLUDE]
            Toast.makeText(this, "Google SIGN-IN Fialed!", Toast.LENGTH_SHORT).show();
            // [END_EXCLUDE]
        }
    }
}

private void getPersonalInfo(final GoogleSignInAccount account)
{
/** Global instance of the HTTP transport. */
        HTTP_TRANSPORT = AndroidHttp.newCompatibleTransport();
/** Global instance of the JSON factory. */
        JSON_FACTORY = JacksonFactory.getDefaultInstance();
    new Thread(
            new Runnable() {
                @Override
                public void run()
                {
                    Collection<String> scopes = new ArrayList<>(Collections.singletonList(Scopes.PROFILE));
                    GoogleAccountCredential credential =
                            GoogleAccountCredential.usingOAuth2(LoginActivity.this,  scopes);
                    credential.setSelectedAccount(
                            new Account(account.getEmail(), "com.google"));
                    People service = new People.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                            .setApplicationName(name /* whatever you like */)
                            .build();
// All the person details
                        Person meProfile = null;
                        try {
                            meProfile = service.people().get("people/me").setRequestMaskIncludeField("people.AgeRange").execute();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
        ).start();
    }
// [START auth_with_google]
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE silent]
    showProgressBar();
    // [END_EXCLUDE]

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(getApplicationContext(), "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }
                    // [START_EXCLUDE]
                    cancelProgressBar();
                    // [END_EXCLUDE]
                }
            });
}
// [END auth_with_google]

private void firebaseSignUp()
{
    Toast.makeText(LoginActivity.this, "Welcome to SignUpActivity",
            Toast.LENGTH_SHORT).show();
    startActivity(new Intent(getApplicationContext(), SignupActivity.class));
    overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
    finish();
}


public void firebaseLogin()
{
    loginFireBaseBtn.setEnabled(false);
    showProgressBar();

    final String email = loginEt.getText().toString();
    final String password = passwordEt.getText().toString();

    if (TextUtils.isEmpty(email))
    {
        cancelProgressBar();
        Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
        loginFireBaseBtn.setEnabled(true);
        return;
    }

    if (TextUtils.isEmpty(password))
    {
        cancelProgressBar();
        Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
        loginFireBaseBtn.setEnabled(true);
        return;
    }

    //authenticate user
    mAuth.signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {

                    if (!task.isSuccessful())
                    {
                        // there was an error
                        if (password.length() < 6)
                        {
                            passwordEt.setError(getString(R.string.minimum_password));
                        }
                        else
                        {
                            Log.e("error auth",getString(R.string.auth_failed));
                            Toast.makeText(getApplicationContext(), getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
                        }
                        cancelProgressBar();
                        loginFireBaseBtn.setEnabled(true);
                    }
                    else
                    {
                        cancelProgressBar();

                            Intent intent = new Intent(getApplicationContext(), AdminActivity.class);
                            overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
                            startActivity(intent);

                            Intent intent = new Intent(getApplicationContext(), NonAdminACtivity.class);
                            overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
                            startActivity(intent);



                        finish();
                    }
                }
            });
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult)
{
    Log.d(TAG, "onConnectionFailed:" + connectionResult);
    Toast.makeText(this, "Google Play Services error.", Toast.LENGTH_SHORT).show();
}
}
导入android.accounts.Account;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.support.annotation.NonNull;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.text.TextUtils;
导入android.util.Log;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.Toast;
导入com.google.android.gms.auth.api.auth;
导入com.google.android.gms.auth.api.signin.GoogleSignInAccount;
导入com.google.android.gms.auth.api.signin.GoogleSignInOptions;
导入com.google.android.gms.auth.api.signin.GoogleSignInResult;
导入com.google.android.gms.common.ConnectionResult;
导入com.google.android.gms.common.Scopes;
导入com.google.android.gms.common.api.GoogleAppClient;
导入com.google.android.gms.tasks.OnCompleteListener;
导入com.google.android.gms.tasks.Task;
导入com.google.api.client.extensions.android.http.AndroidHttp;
导入com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
导入com.google.api.client.http.HttpTransport;
导入com.google.api.client.json.JsonFactory;
导入com.google.api.client.json.jackson2.JacksonFactory;
导入com.google.api.services.people.v1.people;
导入com.google.api.services.people.v1.model.Gender;
导入com.google.api.services.people.v1.model.Person;
导入com.google.firebase.FirebaseApp;
导入com.google.firebase.auth.AuthCredential;
导入com.google.firebase.auth.AuthResult;
导入com.google.firebase.auth.FirebaseAuth;
导入com.google.firebase.auth.FirebaseUser;
导入com.google.firebase.auth.GoogleAuthProvider;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.Collection;
导入java.util.Collections;
导入java.util.List;
公共类LoginActivity扩展了AppCompatActivity实现
View.OnClickListener,
GoogleAppClient.OnConnectionFailedListener
{
专用静态HttpTransport HTTP_传输;
私有静态JsonFactory JSON_工厂;
私有静态最终字符串标记=“GoogleActivity”;
专用静态最终输入RC\U符号\U IN=9001;
私人字符串电子邮件,名称,fname;
私人消防队;
私有FirebaseAuth.AuthStateListener mAuthListener;
私人GoogleapClient MGoogleapClient;
按钮注册TN、登录REBASEBTN、登录OGLEBTN;
EditText loginEt、passwordEt;
私有进程对话;
@凌驾
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u登录);
mAuth=FirebaseAuth.getInstance();
loginEt=(EditText)findViewById(R.id.emailLoginEt);
passwordEt=(EditText)findViewById(R.id.passwordLoginEt);
loginFireBaseBtn=(按钮)findviewbyd(R.id.loginBtn);
signUpBtn=(按钮)findViewById(R.id.signUpBtn);
findviewbyd(R.id.googleSignInButton).setOnClickListener(this);
loginFireBaseBtn.setOnClickListener(此);
signUpBtn.setOnClickListener(此);
mAuthListener=new FirebaseAuth.AuthStateListener(){
@凌驾
AuthStateChanged上的公共void(@NonNull FirebaseAuth FirebaseAuth){
FirebaseUser=firebaseAuth.getCurrentUser();
如果(用户!=null)
{
//用户已登录
if(name!=null&&email!=null&&fname!=null)
{
Toast.makeText(getApplicationContext(),“GOOGLE:\n”+email+“\n”+name+“\n”+fname,Toast.LENGTH\u LONG).show();
Intent Intent=new Intent(getApplicationContext(),NonAdminACtivity.class);
覆盖转换(R.anim.push\u down\u in,R.anim.push\u down\u out);
星触觉(意向);
完成();
}
Log.d(标记为“+user.getUid()”);
}
其他的
{
//用户已注销
Toast.makeText(getApplicationContext(),“已注销”,Toast.LENGTH_LONG.show();
Log.d(标记“onAuthStateChanged:signed_out”);
}
}
};
//[启动配置\登录]
//配置谷歌登录
GoogleSignenOptions gso=新建GoogleSignenOptions.Builder(GoogleSignenOptions.DEFAULT\u登录)
.requestIdToken(getString(R.string.default\u web\u client\u id))
.requestEmail()
.build();
//[结束配置\u登录]
mgoogleapclient=新的Googleapclient.Builder(此)
.enableautomanager(此/*FragmentActivity*/,此/*OnConnectionFailedListener*/)
.addApi(Auth.GOOGLE\u SIGN\u IN\u API,gso)
.build();
}
@凌驾
public void onStart(){
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
@凌驾
公共void onStop(){
super.onStop();
if(mAuthListener!=null){
removeAuthStateListener(mAuthListener);
}
}
公共空间显示进度条()
{
progressDialog=新建progressDialog(LoginActivity.this,
R.style.MyTheme);
progressDialog.setCancelable(假);
progressDialog.setProgressStyle(android.R.style.Widget\u ProgressBar\u Small);
progressDialog.setMessage(“哈哈,不能黑……”);
progressDialog.show();
}
公共作废取消进度条()
{
progressDialog.disclose();
}
@凌驾
公共void onClick(视图v)
{
if(v.getId()==R.id.loginBtn)
{
firebaseLogin();
}
if(v.getId()==R.id.googleSignInButton)
{
import android.accounts.Account;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.Scopes;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.people.v1.People;
import com.google.api.services.people.v1.model.Gender;
import com.google.api.services.people.v1.model.Person;
import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class LoginActivity extends AppCompatActivity implements
        View.OnClickListener,
        GoogleApiClient.OnConnectionFailedListener
{
    private static HttpTransport HTTP_TRANSPORT;
    private static JsonFactory JSON_FACTORY;
private static final String TAG = "GoogleActivity";
private static final int RC_SIGN_IN = 9001;
private String email,name,fname;

private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;


private GoogleApiClient mGoogleApiClient;
Button signUpBtn,loginFireBaseBtn,loginGoogleBtn;
EditText loginEt,passwordEt;
private ProgressDialog progressDialog;


@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    mAuth = FirebaseAuth.getInstance();
    loginEt=(EditText)findViewById(R.id.emailLoginEt);
    passwordEt=(EditText)findViewById(R.id.passwordLoginEt);
    loginFireBaseBtn=(Button)findViewById(R.id.loginBtn);
    signUpBtn= (Button)findViewById(R.id.signUpBtn);

    findViewById(R.id.googleSignInButton).setOnClickListener(this);
    loginFireBaseBtn.setOnClickListener(this);
    signUpBtn.setOnClickListener(this);

    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null)
            {
                // User is signed in
                if (name!=null&&email!=null&&fname!=null)
                {
                    Toast.makeText(getApplicationContext(),"GOOGLE: \n"+email+"\n"+name+"\n"+fname, Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(getApplicationContext(), NonAdminACtivity.class);
                    overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
                    startActivity(intent);
                    finish();
                }
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            }
            else
            {
                // User is signed out
                Toast.makeText(getApplicationContext(),"Signed out", Toast.LENGTH_LONG).show();
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
        }
    };

    // [START config_signin]
    // Configure Google Sign In
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    // [END config_signin]

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

}

@Override
public void onStart() {
    super.onStart();
    mAuth.addAuthStateListener(mAuthListener);
}
@Override
public void onStop() {
    super.onStop();
    if (mAuthListener != null) {
        mAuth.removeAuthStateListener(mAuthListener);
    }
}

public void showProgressBar()
{
    progressDialog = new ProgressDialog(LoginActivity.this,
            R.style.MyTheme);
    progressDialog.setCancelable(false);
    progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
    progressDialog.setMessage("Haha Can't Hack...");
    progressDialog.show();

}


public void cancelProgressBar()
{
    progressDialog.dismiss();

}

@Override
public void onClick(View v)
{
   if (v.getId()==R.id.loginBtn)
   {
        firebaseLogin();
   }
   if (v.getId()==R.id.googleSignInButton)
   {
        googleLogin();
   }
   if (v.getId()==R.id.signUpBtn)
   {
       firebaseSignUp();
   }
}

private void googleLogin()
{
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    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()) {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.getSignInAccount();
            email = account.getEmail();
            name = account.getDisplayName();
            fname = account.getFamilyName();

            getPersonalInfo(account);

            firebaseAuthWithGoogle(account);

        } else {
            // Google Sign In failed, update UI appropriately
            // [START_EXCLUDE]
            Toast.makeText(this, "Google SIGN-IN Fialed!", Toast.LENGTH_SHORT).show();
            // [END_EXCLUDE]
        }
    }
}

private void getPersonalInfo(final GoogleSignInAccount account)
{
/** Global instance of the HTTP transport. */
        HTTP_TRANSPORT = AndroidHttp.newCompatibleTransport();
/** Global instance of the JSON factory. */
        JSON_FACTORY = JacksonFactory.getDefaultInstance();
    new Thread(
            new Runnable() {
                @Override
                public void run()
                {
                    Collection<String> scopes = new ArrayList<>(Collections.singletonList(Scopes.PROFILE));
                    GoogleAccountCredential credential =
                            GoogleAccountCredential.usingOAuth2(LoginActivity.this,  scopes);
                    credential.setSelectedAccount(
                            new Account(account.getEmail(), "com.google"));
                    People service = new People.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                            .setApplicationName(name /* whatever you like */)
                            .build();
// All the person details
                        Person meProfile = null;
                        try {
                            meProfile = service.people().get("people/me").setRequestMaskIncludeField("people.AgeRange").execute();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
        ).start();
    }
// [START auth_with_google]
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE silent]
    showProgressBar();
    // [END_EXCLUDE]

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(getApplicationContext(), "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }
                    // [START_EXCLUDE]
                    cancelProgressBar();
                    // [END_EXCLUDE]
                }
            });
}
// [END auth_with_google]

private void firebaseSignUp()
{
    Toast.makeText(LoginActivity.this, "Welcome to SignUpActivity",
            Toast.LENGTH_SHORT).show();
    startActivity(new Intent(getApplicationContext(), SignupActivity.class));
    overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
    finish();
}


public void firebaseLogin()
{
    loginFireBaseBtn.setEnabled(false);
    showProgressBar();

    final String email = loginEt.getText().toString();
    final String password = passwordEt.getText().toString();

    if (TextUtils.isEmpty(email))
    {
        cancelProgressBar();
        Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
        loginFireBaseBtn.setEnabled(true);
        return;
    }

    if (TextUtils.isEmpty(password))
    {
        cancelProgressBar();
        Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
        loginFireBaseBtn.setEnabled(true);
        return;
    }

    //authenticate user
    mAuth.signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {

                    if (!task.isSuccessful())
                    {
                        // there was an error
                        if (password.length() < 6)
                        {
                            passwordEt.setError(getString(R.string.minimum_password));
                        }
                        else
                        {
                            Log.e("error auth",getString(R.string.auth_failed));
                            Toast.makeText(getApplicationContext(), getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
                        }
                        cancelProgressBar();
                        loginFireBaseBtn.setEnabled(true);
                    }
                    else
                    {
                        cancelProgressBar();

                            Intent intent = new Intent(getApplicationContext(), AdminActivity.class);
                            overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
                            startActivity(intent);

                            Intent intent = new Intent(getApplicationContext(), NonAdminACtivity.class);
                            overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
                            startActivity(intent);



                        finish();
                    }
                }
            });
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult)
{
    Log.d(TAG, "onConnectionFailed:" + connectionResult);
    Toast.makeText(this, "Google Play Services error.", Toast.LENGTH_SHORT).show();
}
}