Google Drive scopes deprecated? - android

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.

Related

Should I use GoogleAuthUtil.getToken(...) or not?

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 !

HistoryApi.readDailyTotal() does not work on Wear device

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();

How to access a list of youtube videos from android using googleapiclient?

I have an android app where I'm logging into g+ and retrieving some info, for which I use a GoogleApiClient object. This is supposed to be able to access all google apis depending on how you set it up. I do this for g+:
mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API, Plus.PlusOptions.builder().build()).addScope(Plus.SCOPE_PLUS_LOGIN).build();
I'm trying to give it permision to access youtube too, but I've been unable to find what apis are available in the addApi method and how to use them. The youtube api docs use a very different method that isn't compatible with what I already have. How can I access youtube with my current code?
add youtube permission then you can use data api.
I'm search for use youtube api with auth.
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
// scope=https://www.googleapis.com/auth/youtube&
.requestScopes(new Scope(YouTubeScopes.YOUTUBE_READONLY))
.requestId()
.requestEmail()
.build();

Autocomplete Google Places sample

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.

Android - Google+ login

I'm following the tutorial from https://developers.google.com/+/mobile/android/sign-in?hl=pt-PT and i'm having some dificulties on enabling the login.
Right on step 2, i have copied to code to my login fragment (where i have the facebook login working smooth), and i get an error on Plus client:
- mPlusClient cannot be resolved to a variable
- The method setVisibleActivities(String, String) is undefined for the type PlusClient.Builder
- The constructor PlusClient.Builder(SplashFragment, SplashFragment, SplashFragment) is undefined
I cant understand where i'm failing, as i've followed the tutorial several times.
The tutorial had been updated in english version. You can check it from https://developers.google.com/+/mobile/android/getting-started?hl=en.
They use GoogleApiClient now.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
It appears the Portuguese version of that page has not been updated to the latest API, hence you are getting errors attempting to use the old API (which has since been deprecated). Consider using the english version instead.
You can also use Social-Auth Library to integrate multiple social platforms with ease...
SocialAuth Android is an Android version of popular SocialAuth Java library. Now you do not need to integrate multiple SDKs if you want to integrate your application with multiple social networks. You just need to add few lines of code after integrating the SocialAuth Android library in your app.
Social Auth

Categories

Resources