I need to use the drive api to create a file with some content from my app, so I followed the "Getting Started" section from Drive api web page.
So I enabled the api on my developer´s console, created an OAuth client id as it says. (Can I use the api if I haven´t paid the 2$5 yet?)
On my settings activity on the onCreate method I'm doing:
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
I'm implementing the methods:
#Override
protected void onStop(){
getGoogleApiClient().disconnect();
super.onStop();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(STATE_RESOLVING_ERROR, resolvingError);
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (resolvingError) {
// Already attempting to resolve an error.
return;
}else if (connectionResult.hasResolution()) {
try {
resolvingError = true;
connectionResult.startResolutionForResult(this,RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
getGoogleApiClient().connect();
}
} else {
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
resolvingError = true;
}
}
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if(requestCode == RESOLVE_CONNECTION_REQUEST_CODE) {
resolvingError = false;
if (resultCode == RESULT_OK) {
if(!getGoogleApiClient().isConnecting() && !getGoogleApiClient().isConnected()){
getGoogleApiClient().connect();
}
}
}
}
#Override
public void onConnected(Bundle bundle) {
Toast.makeText(this, "Success!!! :D :D", Toast.LENGTH_SHORT).show();
}
#Override
public void onConnectionSuspended(int i) {}
Then I call googleApiClient.connect(); on a button onclick method.
I'm getting the select account google drive dialog, select an account and press OK, and I'm getting this error on the connection result:
E/GooglePlayServicesUtil﹕ The specified account could not be signed in.
I searched over the web and cant find the cause of this problem.... maybe I'm doing something wrong on the developers's console... don't know...
UPDATE:
So i delete the project on Google developer´s console and create it again, i also add the Drive Api and enable it, i added a product name on authorization screen, and a new client id with my package name and sha1 id...
also update my manifest,
added to manifest tag:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
to application tag:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
to the activity tag where im doing the connection:
<meta-data
android:name="com.google.android.apps.drive.APP_ID"
android:value="id=<app id i took this id from developers´console>" />
<action android:name="com.google.android.apps.drive.DRIVE_OPEN" />
<data android:mimeType="application/vnd.google-apps.drive-sdk.<app id>" />
i also building a signed apk using the debug keystore to test my app. (on real device).
after all this the error is still rising...
My guess is that there is a problem with the setup you did at the Developer's Console. This discussion may be helpful. – qbix
hello, reading the discussion qbix mention above i just found the cause of my problem...
the default flavor at my project structure had an incorrect Application id, i just change it to my app package "com.xxxxx.yyyyy".
so i beleave when googleApiClient attempted to connect, find diferent package name at id client credencials and deny access....
now is working fine thanx....
Here's my usual checklist:
1/ get the APK in question, push it through an unzipper, like 7-zip. you'll find a folder META-INF with a file CERT.RSA. Get it.
2/ run 'keytool -printcert -file ......\CERT.RSA' and copy/save the SHA1 '11.22.33...99'
3/ get you package name (from manifest?) 'com.blabla.yourproject'
4/ open developers console 'https://console.developers.google.com/project'
5/ in your project, check:
Enabled APIs: drive API
Credentials: Package name: 'com.blabla.yourproject', Fingerprint: '11.22.33...99'
Consent Screen: Email: yourmail#gmail.com , Product Name: 'YourProject'
Good Luck
Pleas try to First normal Google account Login
mGoogleApiClient = new GoogleApiClient.Builder(this).
addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
//.addApi(Drive.API)
//.addScope(Drive.SCOPE_FILE)
.build();
In my case cause was in incorrect 'package name' in OATH client settings:
was: com.blabla.prog
correct one: bla.bla.com.prog
try to ignore the API connection by doing this:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApiIfAvailable(Drive.API)
I've done in this way and everything seems working. I really don't know why, i suppose that the Driver.API creates some problems, and doing in this way you can use the maps,the markers and all that stuff. I know that is not a good answer because i don't provide you a correct explanation, but anyway, it can help.
This type of error may occur in following situations:
If you have used release key SHA1 signing-certificate fingerprint while creating Oauth 2.0 client ID and running your application without signing it with release key (i.e. running with debug key). This is also true for debug key.
If you have used different package name while creating Oauth 2.0 client ID
Another thing that can go wrong is that you create credentials for "API Key" instead of "OAuth 2.0 client ID".
Yeah silly I know.. guide says "Client ID" so I guess I went by the length of the string :)
Related
So there's lots of questions on this, and seemingly lots of (somewhat contradictory) documentation.
I'm simply trying to get a user to sign in to submit a score to a Google Play Services leaderboard in my app.
So they press "show leaderboard" and I begin the sign-in checking process:
public void displayLeaderboard()
{
if (checkPlayServices() == true)
{
// First, sign in.
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
if (account == null)
{
// Need to get sign-in client?
if (_googleSignInClient == null)
{
// Configure sign-in to request the user's ID, email address, and basic profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build();
_googleSignInClient = GoogleSignIn.getClient(this, gso);
}
Intent signInIntent = _googleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, CALLBACK_SIGN_IN_TO_GOOGLE_ACCOUNT);
}
else
{
actualDisplayLeaderboard(account);
}
}
}
So then onActivityResult() does catch the callback, so far so good:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CALLBACK_SIGN_IN_TO_GOOGLE_ACCOUNT)
{
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent()
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try
{
GoogleSignInAccount account = task.getResult(ApiException.class);
// THIS IS WHERE IT FAILS
// **********************
// Signed in successfully.
// ...
}
catch (ApiException e)
{
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
System.out.println("Failed to sign in.");
String message = e.getMessage();
System.out.println(message);
e.printStackTrace();
}
}
}
As indicated above, that is where it fails.
12-10 17:24:54.877 12571-12571/*.*.* W/System.err: com.google.android.gms.common.api.ApiException: 12501:
12-10 17:24:54.877 12571-12571/*.*.* W/System.err: at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
12-10 17:24:54.877 12571-12571/*.*.* W/System.err: at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source)
12-10 17:24:54.887 12571-12571/org.fortheloss.sticknodespro W/System.err: at *.*.*.AndroidLauncher.onActivityResult(AndroidLauncher.java:1013)
Looking at the samples for signing in and leaderboards, my code looks identical.
I feel like I'm going astray with all the Firebase console and/or Google Play Services console (who knows anymore, it's such a mess) OAUTH and SHA-1 stuff I don't know what I need, what I don't need, it's all over the place and it still doesn't work. Some things are for a "web application" - this isn't a web application - I have the credentials there anyway, put in the app, etc - doesn't matter, still doesn't work.
Any pointing in the right direction appreciated.
In typical fashion, the answer comes about after posting the question
This is the fix
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.server_client_id)).requestScopes(Games.SCOPE_GAMES_LITE).build();
Where R.string.server_client_id is as described here https://developers.google.com/identity/sign-in/android/start-integrating#get_your_backend_servers_oauth_20_client_id
(At first, the page it brought me to was for another version of my app, so when I was using that credential, it obviously wasn't working. Then, I realized I needed to create a release build (with my release keystore) to get it to work.)
Things the sample projects fail to show/mention ^
They doesn't even use requestIdToken(...)
EDIT: And the reason...that it doesn't use requestIDToken, despite it being used in nearly every similar StackOverflow answer, is because you're not supposed to. For Android applications. This is because you're supposed to have this in the Android Manifest (app_id taken from Google Play Services console linked app section)
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="#string/app_id" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version"/>
Would be GREAT if Google Play Services would yell at you if you didn't have those included...
My app has been live using Google login for a few years now. I reworked the implementation a few months ago with no issues until recently.
Now, a few weeks ago, login has stopped working. When I attempt it, the login never finishes, but stays in an infinite loop, displaying the "connecting" screen over and over.
internet connectivity is ok
this happens to many users (not sure if it affects ALL Google login users)
I have tried clearing the cache of Google Play services
the Google API client is still connected
I have tried updating all relevant google libraries to the most recent versions
I see this on Android 6 - not sure if other versions are affected
Before I post my code, I want to point out that the login never returns. The callback is never reached until I actively cancel the login (at which point it behaves as expected. I also want to emphasise again that my code has been in place for quite some time before this occurred - maybe something changed on Google side...
I'm out of ideas and in dire need of help. Any ideas?
API client creation in onCreate:
GoogleSignInOptions googleSignInOptions = googleSignInOptionsBuilder
.build();
googleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this,
new GoogleApiClient.OnConnectionFailedListener() {
#Override
public void onConnectionFailed(
#NonNull ConnectionResult connectionResult) {
Logger.error("Google API connection failed");
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.addApi(Games.API)
.build();
Actual Sign-In method:
public void signInWithGoogle() {
logToServer("Google Sign-In Started");
Intent signInIntent = Auth.GoogleSignInApi
.getSignInIntent(googleApiClient);
startActivityForResult(signInIntent,
GameConstants.GOOGLE_REQUEST_CODE_SIGN_IN);
}
Callback (never touched)
#Override
protected void onActivityResult(final int requestCode, int response,
Intent data) {
super.onActivityResult(requestCode, response, data);
if (requestCode == GameConstants.GOOGLE_REQUEST_CODE_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi
.getSignInResultFromIntent(data);
handleGoogleSignInResult(result);
}
}
...
If someone still has this issue, this is how to fix it:
You probably forgot to switch the Google authentification on Firebase
You simply need to login to console.firebase.google.com --> Click on Authentification on the left --> Click on Sign-in Method --> Select Google and toggle the switch to activate.
I can sign in my app with Google account at first several times.
Everything is fine.
But if I sign in and out about 20 times in a one or two minutes.
Google sign in failed and in onActivityResult function, it returns error code 12501, resultCode = 0;
I'm using the phone: Nexus 6, Android 5.1.1
Here is my code:
private GoogleSignInOptions mGso;
private GoogleApiClient mGac;
public void init(#NonNull final BaseActivity activity) {
mGso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(activity.getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGac = new GoogleApiClient.Builder(activity)
.enableAutoManage(activity /* FragmentActivity */, new GoogleApiClient.OnConnectionFailedListener() {
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
ToastUtils.show(activity, R.string.login_failed);
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, mGso)
.build();
}
public void signIn(#NonNull final BaseActivity activity,
#NonNull GoogleSignInCallback callback,
#NonNull final OnLoadingListener<PlatformUserEntity> listener) {
callback.registerCallback(listener);
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGac);
activity.startActivityForResult(signInIntent, REQUEST_GOOGLE_SIGNIN);
// disconnect the client
mGac.stopAutoManage(activity);
mGac.disconnect();
}
Here is gradle:
compile 'com.google.android.gms:play-services-base:9.6.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'
compile 'com.google.android.gms:play-services-auth:9.6.1'
Fisrt, I init the GoogleApiClient with a FragmentActivity, then signIn function starts the Acitvity. GoogleSignInCallback is registered in the onActivityResult function. Then disconnect the Client because every time the sign in button is clicked, the init function will be invoked.
I doubt that I use stopAutoManage() too early but it seems like not true.
So I'm confused, which part might be wrong?
I noticed the log:
Could not set socket write timeout: null
12-03 17:21:43.859 264-264/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
12-03 17:21:43.902 1946-12870/? W/Conscrypt: Could not set socket write timeout: null
12-03 17:21:44.327 21168-21168/? W/AccountChipsFragment: Recording consent failed.
12-03 17:21:44.657 29359-29782/? E/TokenRequestor: You have wrong OAuth2 related configurations, please check. Detailed error: UNREGISTERED_ON_API_CONSOLE
12-03 17:21:44.664 812-1072/? W/ActivityManager: getRunningAppProcesses: caller 10145 does not hold REAL_GET_TASKS; limiting output
12-03 17:21:44.697 21168-21168/? W/AutoManageHelper: Unresolved error while connecting client. Stopping auto-manage.
It said "You have wrong OAuth2 related configuration", but I could use the web client id to request the IdToken at the first time.
It just makes me more confused.
I also found a strange thing. If I install the apk which is built locally, this error never happened. If I download from google play store, this error ocurred. But there is no difference between these two apks because I deliver google store with the local one.
Finally I found the reason.
My apk was signed again by our company's release procedure.
The procedure used another keystore so my sha1 key was changed.
I configure the new sha1 key in google develop console, this bug is solved.
But I'm still confused that, if I use the debug keystore apk, got sign in successfully and uninstall it, then I install the google play apk which has different sha1 key, google sign in can work some times.It won't tell me wrong immediately.
if your code working well at first time then
you can try that way,
private GoogleSignInOptions mGso;
private GoogleApiClient mGac;
public void signIn(#NonNull final BaseActivity activity,
#NonNull GoogleSignInCallback callback,
#NonNull final OnLoadingListener<PlatformUserEntity> listener) {
mGso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(activity.getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGac = new GoogleApiClient.Builder(activity)
.enableAutoManage(activity /* FragmentActivity */, new GoogleApiClient.OnConnectionFailedListener() {
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
ToastUtils.show(activity, R.string.login_failed);
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, mGso)
.build();
callback.registerCallback(listener);
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGac);
activity.startActivityForResult(signInIntent, REQUEST_GOOGLE_SIGNIN);
// disconnect the client
mGac.stopAutoManage(activity);
mGac.disconnect();
}
or
as your log mention:
You have wrong OAuth2 related configurations, please check. Detailed error: UNREGISTERED_ON_API_CONSOLE
So, Problem can be:
1. Sh1 key add in your api
2. Api key type like for android or web
3. Check Internet Connection
Sorry, for my english.
I hope this will help you. thanks
Try the solution in this SO question, by changing your code and using this code
mGso = newGoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(AuthenticatedActivity.this.getResources()
.getString(R.string.server_client_id))
.requestEmail()
.build();
For more information, check this another SO question if it can help you.
According to This Official Post
I'm following below steps to integrate Place Picker UI dialog with Map.
launcher code
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
inside onActivityResult()
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(this, data);
tvChooseLocation.setText(place.getName());
}
}
I have added all permissions & API_KEY in Manifest file
Problem is I am not able to select location from Place Picker dialog.
Select button is disabled by default.
I have solved this so I don't quite know which one of these steps solves it
In console.developer.google.com
I enable Places API and Maps API, and download the json from here.
Also, get the API key from Credential page.
In Android Studio
In manifest, add in between <application> ... </application>
<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_KEY_FROM_CREDENTIAL_PAGE"/>
In onCreate(), add this (though I don't quite sure this is needed or not)
private GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.enableAutoManage(this, this)
.build();
Everything else just follow the tutorial in here. Also, I tested it in release version. If you still have the same problem, try make a release one. I failed to get the location in emulator but it work just fine in my phone.
Hopefully this can help anyone in the future.
Try enabling google places api from google developer console
Link to console
--Wanted to comment though but do not have permission.
I'm using dynamic links for my app.
I've followed the tutorial step-by-step and I'm able to open the app by clicking on the link posted on facebook.
But when I invoke getInvitation, I always have CANCELED as status of AppInviteInvitationResult.
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, false).setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
#Override
public void onResult(#NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
// [END_EXCLUDE]
} else {
Log.d("StartActivity", "getInvitation: no deep link found.");
}
}
});
Into debug, I can see that result.getStatus() returns CANCELED, but the click on lick open the app correctly.
Where I'm wrong?
EDIT: The link that I'm using is:
https://wft4z.app.goo.gl/?link=https://aqld.it/testlink/112972&al=aqld://test/about?params%3D17363&apn=com.project.mydeeplink
The filter on manifest:
The status is canceled when no intent has been received. I was wondering the same thing and it turned out that my links created in firebase web page were wrong. I wrote some ideas on how to debug the url problem as an answer to another question. If you have the same problem as I did, they should be helpful:
https://stackoverflow.com/a/37615175/4025606
Doesn't directly answer your question but you could eliminate badly formed urls as a root cause by using this page to create firebase dynamic links for both ios and Android: http://fdl-links.appspot.com/
Just double-check if you have added the SHA-1 in the firebase console and the added SHA-1 matches the SHA1 of the generated APK. I was seeing the same issue - result.getStatus() returning CANCELED prior to this, but after adding the SHA-1 on firebase console, it started working fine. :)