简体   繁体   English

如何通过Google登录API获取用户国家/地区名称?

[英]How to get user country name by google signin API?

I am new in android developement. 我是android开发的新手。 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. 在此应用中,需要用户所在国家,请Plz帮助我,当用户通过Google帐户登录时如何获取用户所在国家。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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