Reputation: 1682
Why I'm getting this error? I already created a project in Google Developer Console, enabled Drive API and Google+ API and added "Android Client Id" with my signed apk's sha1 (I already shared as beta on google play console by the way).
I get permissions GET_ACCOUNTS
and when I choose my G+ mail in list, I'm getting this error:
D/G+: Connection failed4ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent
Do I have to add client_id.json
somewhere in my project folder? (I just created it in Google Developer Console for Drive API.)
codes:
// initialize g+ api client
if (Sp.getBoolean("plus_pic", false)) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.build();
}
and:
@Override
public void onConnected(Bundle bundle) {
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
Person.Image personImage;
Person.Cover.CoverPhoto personCover;
try {
personImage = currentPerson.getImage();
personCover = currentPerson.getCover().getCoverPhoto();
} catch (Exception e) {
Log.e("G+ COnnection error"," ->"+e.toString());
personCover = null;
personImage = null;
}
if (personCover != null && personImage != null) {
String imgUrl = personImage.getUrl();
Log.e("g+ connection","cover and pic not null");
// getting full size image
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(imgUrl);
stringBuilder.delete(imgUrl.length() - 6, imgUrl.length());
Log.d("G+", stringBuilder.toString());
mGoogleName.setText(currentPerson.getDisplayName());
mGoogleId.setText(accountName);
// setting cover pic
ImageLoader.getInstance().loadImage(personCover.getUrl(), displayImageOptions, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
drawerHeaderParent.setBackgroundColor(Color.parseColor("#ffffff"));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
drawerHeaderView.setBackground(new BitmapDrawable(loadedImage));
} else
drawerHeaderView.setBackgroundDrawable(new BitmapDrawable(loadedImage));
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
super.onLoadingFailed(imageUri, view, failReason);
drawerHeaderView.setBackgroundResource(R.drawable.app_header);
drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab == 1 ? skinTwo : skin)));
}
@Override
public void onLoadingStarted(String imageUri, View view) {
super.onLoadingStarted(imageUri, view);
drawerHeaderView.setBackgroundResource(R.drawable.app_header);
drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab == 1 ? skinTwo : skin)));
}
});
// setting profile pic
ImageLoader.getInstance().loadImage(stringBuilder.toString(), displayImageOptions, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
drawerProfilePic.setImageBitmap(loadedImage);
drawerProfilePic.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
super.onLoadingFailed(imageUri, view, failReason);
}
});
} else {
Toast.makeText(this, getResources().getText(R.string.no_cover_photo), Toast.LENGTH_SHORT).show();
drawerHeaderView.setBackgroundResource(R.drawable.app_header);
drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab == 1 ? skinTwo : skin)));
}
}
}
@Override
public void onConnectionSuspended(int i) {
Log.d("G+", "Connection suspended");
new Thread(new Runnable() {
@Override
public void run() {
if (mGoogleApiClient != null) {
mGoogleApiClient.connect();
}
}
}).run();
}
public void onConnectionFailed(final ConnectionResult result) {
Log.d("G+", "Connection failed"+ result.getErrorCode()+result.toString());
if (!mIntentInProgress && result.hasResolution()) {
new Thread(new Runnable() {
@Override
public void run() {
try {
mIntentInProgress = true;
startIntentSenderForResult(result.getResolution().getIntentSender(),
RC_SIGN_IN, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
mIntentInProgress = false;
if (mGoogleApiClient != null) {
mGoogleApiClient.connect();
}
}
}
}).run();
}
}
and:
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == RC_SIGN_IN && !mGoogleApiKey && mGoogleApiClient != null) {
new Thread(new Runnable() {
@Override
public void run() {
mIntentInProgress = false;
mGoogleApiKey = true;
// !mGoogleApiClient.isConnecting
if (mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
} else
mGoogleApiClient.disconnect();
}
}).run();
}
Upvotes: 2
Views: 1333
Reputation: 1503
In my cause i wrongly used release SHA1 key to generate API in developer console. Then created SHA1 key with debug.keystore and updated in my api credentials. Its started working.
keytool -list -v -keystore "C:\Users\<user>n\.android\debug.keystore" -alias androiddebugkey -storepass andro
id -keypass android
Upvotes: 0
Reputation: 2998
You got the error SIGN_IN_REQUIRED
because the client attempted to connect to the service but the user is not signed in.
The client may choose to continue without using the API. Alternately, if
hasResolution()
returns true the client may call [startResolutionForResult(Activity, int)
](https://developers.google.com/android/reference/com/google/android/gms/common/ConnectionResult.html#startResolutionForResult(android.app.Activity, int)) to prompt the user to sign in. After the sign in activity returns withRESULT_OK
further attempts should succeed.
Based from this forum, try to resolve this issue by going to the Google API console from your gmail account. There you will see a disable button in front of Google Drive API. You will see a gear or setting button, click on it and generate oAuth token.
Here are some related threads:
Hope this helps!
Upvotes: 1