Reputation: 4563
In my android app i want to integrate Google+ services. For that i referred quick start guide link according to that link i have done all steps but i have problem in performing 3rd step(a,b,c points) of "Create an OAuth 2.0 Client ID ".As google developer has changed its entire console design i am not getting from where i will get OAuth clien ID ? I have done other steps properly.I referred PlusSampleActivity
which is provided with AndroidSDK and i am using google-play-services_lib
library but that demo doesn't run properly. When i try to sign in, it opens dialog to choose gmailID after selecting when i go further it doesn't do login and shows toast message "An internal error has occurred". Please help to solve this issue. I referred many links but most of them might be using old play-service lib ,thus i couldn't get much idea about that.I also went through many questions on stackoverflow regarding this issue but they don't meet my requirements.I also tried to debug my code but Error log
doesn't show any message regarding this. If anyone know good tutorial-example or solution for this issue then please help me to solve it.
Thank you.
Code :
package com.google.android.gms.samples.plus;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.plus.PlusClient;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class SignInActivity extends Activity implements OnClickListener,
PlusClient.ConnectionCallbacks, PlusClient.OnConnectionFailedListener,
PlusClient.OnAccessRevokedListener {
private static final int DIALOG_GET_GOOGLE_PLAY_SERVICES = 1;
private static final int REQUEST_CODE_SIGN_IN = 1;
private static final int REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES = 2;
private TextView mSignInStatus;
private PlusClient mPlusClient;
private SignInButton mSignInButton;
private View mSignOutButton;
private View mRevokeAccessButton;
private ConnectionResult mConnectionResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_in_activity);
mPlusClient = new PlusClient.Builder(this, this, this)
.setActions(MomentUtil.ACTIONS)
.build();
mSignInStatus = (TextView) findViewById(R.id.sign_in_status);
mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);
mSignInButton.setOnClickListener(this);
mSignOutButton = findViewById(R.id.sign_out_button);
mSignOutButton.setOnClickListener(this);
mRevokeAccessButton = findViewById(R.id.revoke_access_button);
mRevokeAccessButton.setOnClickListener(this);
}
@Override
public void onStart() {
super.onStart();
mPlusClient.connect();
}
@Override
public void onStop() {
mPlusClient.disconnect();
super.onStop();
}
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.sign_in_button:
int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (available != ConnectionResult.SUCCESS) {
showDialog(DIALOG_GET_GOOGLE_PLAY_SERVICES);
return;
}
try {
mSignInStatus.setText(getString(R.string.signing_in_status));
mConnectionResult.startResolutionForResult(this, REQUEST_CODE_SIGN_IN);
} catch (IntentSender.SendIntentException e) {
// Fetch a new result to start.
mPlusClient.connect();
}
break;
case R.id.sign_out_button:
if (mPlusClient.isConnected()) {
mPlusClient.clearDefaultAccount();
mPlusClient.disconnect();
mPlusClient.connect();
}
break;
case R.id.revoke_access_button:
if (mPlusClient.isConnected()) {
mPlusClient.revokeAccessAndDisconnect(this);
updateButtons(false /* isSignedIn */);
}
break;
}
}
@Override
protected Dialog onCreateDialog(int id) {
if (id != DIALOG_GET_GOOGLE_PLAY_SERVICES) {
return super.onCreateDialog(id);
}
int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (available == ConnectionResult.SUCCESS) {
return null;
}
if (GooglePlayServicesUtil.isUserRecoverableError(available)) {
return GooglePlayServicesUtil.getErrorDialog(
available, this, REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES);
}
return new AlertDialog.Builder(this)
.setMessage(R.string.plus_generic_error)
.setCancelable(true)
.create();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_SIGN_IN
|| requestCode == REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES) {
if (resultCode == RESULT_OK && !mPlusClient.isConnected()
&& !mPlusClient.isConnecting()) {
// This time, connect should succeed.
mPlusClient.connect();
}
}
}
@Override
public void onAccessRevoked(ConnectionResult status) {
if (status.isSuccess()) {
mSignInStatus.setText(R.string.revoke_access_status);
} else {
mSignInStatus.setText(R.string.revoke_access_error_status);
mPlusClient.disconnect();
}
mPlusClient.connect();
}
@Override
public void onConnected(Bundle connectionHint) {
String currentPersonName = mPlusClient.getCurrentPerson() != null
? mPlusClient.getCurrentPerson().getDisplayName()
: getString(R.string.unknown_person);
mSignInStatus.setText(getString(R.string.signed_in_status, currentPersonName));
updateButtons(true /* isSignedIn */);
}
@Override
public void onDisconnected() {
mSignInStatus.setText(R.string.loading_status);
mPlusClient.connect();
updateButtons(false /* isSignedIn */);
}
@Override
public void onConnectionFailed(ConnectionResult result) {
mConnectionResult = result;
updateButtons(false /* isSignedIn */);
}
private void updateButtons(boolean isSignedIn) {
if (isSignedIn) {
mSignInButton.setVisibility(View.INVISIBLE);
mSignOutButton.setEnabled(true);
mRevokeAccessButton.setEnabled(true);
} else {
if (mConnectionResult == null) {
// Disable the sign-in button until onConnectionFailed is called with result.
mSignInButton.setVisibility(View.INVISIBLE);
mSignInStatus.setText(getString(R.string.loading_status));
} else {
// Enable the sign-in button since a connection result is available.
mSignInButton.setVisibility(View.VISIBLE);
mSignInStatus.setText(getString(R.string.signed_out_status));
}
mSignOutButton.setEnabled(false);
mRevokeAccessButton.setEnabled(false);
}
}
}
Upvotes: 2
Views: 2857
Reputation: 4563
I solved that issue. As I was not able to create OAuth Client ID
in new google api console, I was facing this problem. Then I did all steps from scratch in old api-console and I could generate OAuth ClientID
and now I am able to integrate it in my app.
Upvotes: 0