I am attempting to utilize the GoogleAuthUtil library for a Xamarin Android project to retrieve an oauth2 token for the Google account on the Android device. The particular scope I am authenticating for is for YouTube: https://www.googleapis.com/auth/youtube, for the purpose of being able to subscribe the user to a specific YouTube channel. I am making the call from an activity (hence passing in 'this' as the first parameter). The second parameter is the email address retrieved from the AccountManager. The third parameter is the scope.
The GoogleAuthUtil is included as a Xamarin component (Google Play Services (Froyo)) as the app is currently targeting API 8+).
I am using the GetToken method as follows:-
GoogleAuthUtil.GetToken(this, googleAccount.Name, "oauth2:https://www.googleapis.com/auth/youtube");
This call throws a GoogleAuthException as follows:-
{Android.Gms.Auth.GoogleAuthException: Exception of type 'Android.Gms.Auth.GoogleAuthException' was thrown. at Android.Runtime.JNIEnv.CallStaticObjectMethod (IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00064] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/a1e3982a/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1160 at Android.Gms.Auth.GoogleAuthUtil.GetToken (Android.Content.Context p0, System.String System.String p2) [0x00000] in <filename unknown>:0 at XXXXX+<>c__DisplayClass4.<OnCreate>b__0 (System.Object x) [0x00002] in XXXXX --- End of managed exception stack trace ---com.google.android.gms.auth.GoogleAuthException: Unknown at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) at dalvik.system.NativeStart.run(Native Method) Android.Gms.Auth.GoogleAuthException
Note: I have replaced the namespaces and file names with XXXXX for integrity.
I have tried a number of different strings for the scope based upon other articles and questions on this forum and others, but all seem to yield the 'UNKNOWN' error, or in some cases 'INVALID_SCOPE' which presumably is a backwards step.
Most recently I have tried a scope as follows:-
"oauth2:server:client_id:xxxxxxxxxxx.apps.googleusercontent.com:api_scope:https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/youtube");
as suggested in the following Q/A: Similar Question, but I still receive the same 'UNKNOWN' error.
Any thoughts on why this is occurring and/or an alternative way to implement this on Android would be appreciated. I would rather not implement the WebView approach if all of the details required to obtain this token are already on the device.