I'm trying to run the Google Place Code Sample, but I am not able to do it.
I am receiving error messages like:
Error getting autocomplete prediction API call: Status{statusCode=TIMEOUT, resolution=null}
I added my Google Map V2 ApiKey to the Manifest, and signed the app with the right certificate, so it seems that the key could be here:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, 0 /* clientId */, this)
.addConnectionCallbacks(this)
.addApi(Places.GEO_DATA_API)
.build();
I am not sure what is supposed to be in the clientId slot, and there is not too much info out there. Just other people with the same problem but without solution.
By the way if somebody wants to take a look to the complete code it is here:
https://github.com/googlesamples/android-play-places/issues/3
This error can be caused by not enabling the Places API for Android in your Google Developer Console (This is different from the regular Places API).
It can also be caused if you set your API key using the old 'maps' identifier instead of com.google.android.geo.API_KEY, when adding the google meta-data to your application manifest.
Related
Background:
I need to authenticate on my server back-end so I know the client is genuine. In my Android game I connect to Games.API via GoogleApiClient.
I only want to have to sign in once, which I want to do via Games.API, as this gives me many advantages (Google Play Games leaderboards, achievements, etc.)
I have been able to get an authorisation token using GoogleAuthUtil.getToken(...) which I can do after I sign into Games.API, which seems to give me a token. Good so far.
But Google says this is not safe and says I should migrate to ID token flow instead. But, as I understand it this approach would require me to use
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
which means instigating an additional sign in to that for Games.API. Furthermore, it is not possible to addApi both Games.API and Auth.GOOGLE_SIGN_IN_API to the same GoogleApiClient !
Ok, so upgrade to the latest google-play-services (at least r29), using which I can use Games.API with Games.getGamesServerAuthCode(...) to obtain an auth token for my server. But this has two problems: (1) it requires Android 6.0 or above which blocks out 80% of the market, and (2) it's deprecated !
Question:
Should I use GoogleAuthUtil.getToken(...) or not, and if not what are my options given that I only want to sign in using Games.API ?
By sign in I mean present the user with log in visuals. I don't mind signing into something else so long as the user does not have to interact with the sign in...
Note:
I originally asked this question when I first started out. The current question hopefully clarifies the situation.
Firstly, I should not use GoogleAuthUtil.getToken(...). It's deprecated; end of.
To achieve what I want I found the following works perfectly... whether it's the best way I have no idea.
First, sign in using Auth.GOOGLE_SIGN_IN:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(
GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken("YOUR-SERVER-CLIENT-ID")
.build();
mGoogleApiClientForSignIn = new GoogleApiClient.Builder(mActivity, this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleApiClientForSignIn.connect();
On success this will eventually call onConnected(...) from where you can negotiate a second sign in to Games.API. This has to be performed separately on a new GoogleApiClient because you can't mix Games.API and Auth.GOOGLE_SIGN_IN:
mGoogleApiClientForGames = new GoogleApiClient.Builder(mActivity, this, this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)
.build();
mGoogleApiClientForGames.connect();
As per the new Play Games Permissions update for 2016, the GoogleSignIn only appears once per game (even between devices !), after which the user is not presented with any visual log in screens for GoogleSignIn. The only visual login will be the Saved Games snapshot selection screen.
This works with Android 2.3 (use google-play-services r28) and without deprecation warnings. Huzzah !
I'm trying to implement Google Drive to my Android app and I cannot even connect to Api client. And I don't know why:
I have configured project and credentials in developer console for ~/.android/debug.keystore (values seems to be correct)
I have copy-pasted code from Drive for Android Documentation -> In method onConnectionFailed() I'm calling connectionResult.startResolutionForResult() if connectionResult.hasResolution()
In onActivityResult for matching requestCode I'm receiving resultCode == 0 (RESULT_CANCELLED) even when i select my account
Do you have any idea why? I also tried to add:
<meta-data
android:name="com.google.android.apps.drive.APP_ID"
android:value="----"/>
into Manifest which is not mentioned on documentation page but on some SO posts.
Thanks for help
Edit:
I have also tried to use enableAutoManage
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.build();
instead of manualy configuring connection and connectionFailed callbacks:
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
It returns me error code 13 in onConnectionFailed method. Based on documentation it seems, that this returns when:
OnConnectionFailedListener passed to
enableAutoManage(FragmentActivity,
GoogleApiClient.OnConnectionFailedListener) when the user choses not
to complete a provided resolution. For example by canceling a dialog.
But i didn't cancelled it.
I'm testing it on Nexus 5x - Android N
I found where the problem was while reading something about wallet api
I've just needed to create OAuth client ID not API key
Go to Developer Console > Credentials
Click "create credentials" > OAuth client ID > Android
Fill the details
Create
Open OAuth consent screen (on Credentials page)
Fill email and product name
Save
Now it works!
JUST IN CASE
#VizGhar solution is right if you missed up Client ID creation process. But I get resultCode=0 and everything was fine with my OAuth client ID. And finally I solved it, so I created SHA1 as per documentation, but I run my app in debug mode (Build variant) and always had resultCode=0. Just switched to release mode and problem is gone, now resultCode=-1 as expected.
I'm developing watch face for Android Wear. I want to show on the face the steps recorded only by the wear device. According to Google Documentation this is possible with HistoryApi.readDailyTotal()
According to the documentation:
The system does not require authorization to access the TYPE_STEP_COUNT_DELTA data type from the HistoryApi.readDailyTotal() method. This can be useful if you require step data for use in areas where you are unable to show the permissions panel (for example, Android Wear watch faces and activities or widget activities). For more information on how to use this data in a watch face, see Showing Information in Watch Faces.
Unfortunately this does not work for me - GoogleApiClient always returns Connection failed: 5 - This means:The client attempted to connect to the service with an invalid account name specified.
This is my client:
mFitnessApiClient = new GoogleApiClient.Builder(MyWatchFace.this)
.addApi(Fitness.HISTORY_API)
.addScope(Fitness.SCOPE_ACTIVITY_READ)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Any idea how to tackle this problem? I'm facing hard time with this.
I've had similar issues getting the total on the wearable (local only), and this worked for me: do not add any scopes, and be sure to call useDefaultAccount. Hope this helps!
Ex:
mFitnessApiClient = new GoogleApiClient.Builder(MyWatchFace.this)
.addApi(Fitness.HISTORY_API)
// Do not add any scopes if using the client on the watch
.addConnectionCallbacks(this)
.useDefaultAccount() // Use the default account
.addOnConnectionFailedListener(this)
.build();
I am using this tutorial to create a autocomplete search box. I have created a custom adapter to populate my autocomplete text box. the following code should give me autocomplete suggestions.
mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
.addApi(Places.GEO_DATA_API)
.enableAutoManage(this, GOOGLE_API_CLIENT_ID, this)
.addConnectionCallbacks(this)
.build();
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient,
constraint.toString(),
mBounds, null);
unfortunately this gives me an error:
{statusCode=ERROR_OPERATION_FAILED, resolution=null}
I checked the official documentation, there are no reference of ERROR_OPERATION_FAILED error.
There are no problems with my API key I guess, because I had another application with a working API key. I used the working API key in this application, still it is not working.
I tried turning off mobile data. Surprisingly the error is still there. The error comes instantly as I type (i.e. It looks like its not even going to the google service at all).
what could be the reason of this error?
The AndroidManifest.xml should include permission :
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
and tag
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version"/>
I'm writing an app that would play media straight off Google Drive.
Google docs mention
https://www.googleapis.com/auth/drive.readonly
scope (see here: https://developers.google.com/drive/web/scopes) that seems exactly to be what I need. Yet, it seems that Android drive API supports only two of scopes mentioned there:
Drive.SCOPE_FILE
Drive.SCOPE_APPFOLDER
so I've tried several non-standard scopes like this:
mGoogleApiClient = new GoogleApiClient.Builder(XenoAmp.getContext())
.addApi(Drive.API)
//.addApi(DriveScopes.)
//.addScope(Drive.SCOPE_APPFOLDER)
.addScope(Drive.SCOPE_FILE)
.addScope(new Scope("https://www.googleapis.com/auth/drive"))
//.addScope(new Scope("https://www.googleapis.com/auth/drive.readonly"))
//.addScope(new Scope("https://www.googleapis.com/auth/drive.metadata.readonly"))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
Yet my logcat complains:
03-29 12:53:58.935: E/ClientConnectionOperation(9953): com.google.android.gms.drive.auth.c: Authorization failed: Unsupported scope: https://www.googleapis.com/auth/drive
So - is drive scope no more supported? How can I get access to all user media files on Goodle Drive then?
Yes, the DRIVE scope is not supported in GDAA. If you need it, you have to go with the REST API. GDAA is not a 'newer' API, it is a different API. Both will be around for a while. You can compare these two here.