简体   繁体   中英

How to get user country name by google signin API?

I am new in android developement. I am developing mobile app. In this app, It is need to user country, Plz help to me, how to get user country when user sign in by google account. I am wasting much more time, but did not get any solution.

Scope myScope = new Scope("https://www.googleapis.com/auth/user.birthday.read");
    Scope myScope2 = new Scope(Scopes.PLUS_ME);
    Scope myScope3 = new Scope(Scopes.PROFILE); //get name and id

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(myScope, myScope2, myScope3)
            .requestEmail()
            .requestProfile()
            .requestEmail()
            .build();



mGoogleApiClient = new GoogleApiClient //this is the line of the error
                .Builder(this)
                .enableAutoManage(this,(GoogleApiClient.OnConnectionFailedListener) this)
                .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                    @Override
                    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                        Toast.makeText(getApplicationContext(),"La conexión alcliente api de Google ha fallado",Toast.LENGTH_LONG).show();
                    }
                })
                //.addApi(Plus.API)
                .addApi(Auth.GOOGLE_SIGN_IN_API,gso)
                .build();

 GoogleSignInAccount acct = result.getSignInAccount();
        System.out.println("Display Name:="+acct.getDisplayName());
        System.out.println("Display Name:="+acct.getEmail());
        System.out.println(""+ acct.getGivenName());
        System.out.println(""+acct.getFamilyName());

抱歉,但是在2019年4月2日关闭了Google(+)消费者(个人)帐户的API和登录API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM