I am trying to login using Google Plus in Android. When I am pressing 
Google Plus button, it is giving me the profile which need to be choosen. 
After choose the google plus account, onConnected() method is getting 
called. Then I am trying fetch the user data. But I am getting the 
exception saying:

Error requesting visible circles: Status{statusCode=NETWORK_ERROR, 
resolution=null}


Here is my complete code which I have written:

public class LoginActivity extends AppCompatActivity implements 
View.OnClickListener, GoogleApiClient.ConnectionCallbacks, 
GoogleApiClient.OnConnectionFailedListener, 
ResultCallback<People.LoadPeopleResult> 
 {

    private GoogleApiClient mGoogleApiClient;

    private ConnectionResult mConnectionResult;

    private boolean mIntentInProgress;

    private boolean mSignInClicked;

    private static final int REQUEST_RESOLVE_ERROR = 1001;

     @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_login);

        mBtnGPlus = (SignInButton)findViewById(R.id.btn_sign_in);
        mBtnGPlus.setOnClickListener(this);
        mBtnGPlus.setSize(SignInButton.SIZE_STANDARD);

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API, Plus.PlusOptions.builder().build())
                .addScope(Plus.SCOPE_PLUS_PROFILE)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .build();

    }

     protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }


    @Override
    public void onClick(View v)
    {
        if(v == mBtnGPlus)
        {
            onGPlusLogin();
        }
    }


    private void onGPlusLogin()
    {
        Logger.d("button clicked");
        if (!mGoogleApiClient.isConnecting()) {
            mSignInClicked = true;
            Logger.d("connecting gplus");
            resolveSignInError();
        }
    }

     private void resolveSignInError() {
        Logger.d("resolveSignInError");
        if (mConnectionResult.hasResolution())
        {
            Logger.d("inside hasResolution");
            try {
                mIntentInProgress = true;
                mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
            } catch (IntentSender.SendIntentException e)
            {
                Logger.d("exception came  "+e.getMessage());
                mIntentInProgress = false;
                mGoogleApiClient.connect();
            }
        }
    }

    @Override
    public void onResult(People.LoadPeopleResult peopleData) {

        Logger.d("status code onResult " 
+peopleData.getStatus().getStatusCode());
        if (peopleData.getStatus().getStatusCode() == 
CommonStatusCodes.SUCCESS) {
            PersonBuffer personBuffer = peopleData.getPersonBuffer();
            try {
                int count = personBuffer.getCount();
                for (int i = 0; i < count; i++) {
                    Logger.d("Display name: " + 
personBuffer.get(i).getDisplayName());
                }
            } finally {
                personBuffer.release();
            }
        } else {
            Logger.d("Error requesting visible circles: " + 
peopleData.getStatus());
        }
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
       if (!mIntentInProgress) {
            // Store the ConnectionResult for later usage
            mConnectionResult = result;
            if (mSignInClicked) {
                // The user has already clicked 'sign-in' so we attempt to
                // resolve all
                // errors until the user is signed in, or they cancel.
                resolveSignInError();
            }
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Logger.d("OnActivity result::::   " + resultCode);
        if (requestCode == RC_SIGN_IN)
        {
            Logger.d("OnActivity result 5555::::   " + resultCode);
            if (resultCode != RESULT_OK)
            {
                Logger.d("OnActivity result 666666   " + resultCode);
                mSignInClicked = false;
            }

            mIntentInProgress = false;

            if (!mGoogleApiClient.isConnecting()) {
                Logger.d("OnActivity result::: 777777   " + resultCode);
                mGoogleApiClient.connect();
            }
        }
    }

    @Override
    public void onConnectionSuspended(int arg0) {
        Logger.d("onConnectionSuspended::::   ");
        mGoogleApiClient.connect();
    }


    @Override
    public void onConnected(Bundle arg0) {
        mSignInClicked = false;
        Logger.d("OnConnected::::   ");
        Plus.PeopleApi.loadVisible(mGoogleApiClient, null)
                .setResultCallback(this);
        Logger.d("OnConnected::::   
"+(Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) == null));
        if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
            Person currentPerson = 
Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
            String personName = currentPerson.getDisplayName();
            String personGooglePlusProfile = currentPerson.getUrl();
        }


        }


Here is manifest file relevant to it:

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.intent.action.CALL_PRIVILEGED" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />

<application
        android:name=".util.DBOpenHelper"
        android:allowBackup="true"
        android:icon="@drawable/dicon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name=".ui.Splashscreen"
            android:theme="@style/AppTheme.Dark" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.LoginActivity"
            android:theme="@style/AppTheme.Dark" >
        </activity>
        <activity
            android:name=".ui.RegistrationActivity"
            android:label="@string/title_activity_registration"
            android:theme="@style/AppTheme.Dark" >
        </activity>
        <activity
            android:name=".ui.HomeScreen"
            android:label="@string/title_activity_home_screen"
            android:theme="@style/AppTheme.Inside" >
        </activity>
        </activity>
    </application>


Can anyone please help me on this?

-Arindam.

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/c2540f10-a5b6-4448-b01a-31f04154db27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to