all i want is to login via youtube on my app. what am I missing?
`import 'dart:async';
import 'dart:convert' show json;
import 'package:googleapis_auth/auth_io.dart';
import "package:http/http.dart" as http;
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:googleapis_auth/auth.dart';
class AuthService {
String oAuthClientId = 'HIDDEN';
var accountCredentials = new ServiceAccountCredentials.fromJson({
"private_key_id": "",
"private_key": "",
"client_email": "@developer.gserviceaccount.com",
"client_id": ".apps.googleusercontent.com",
"type": "service_account"
});
static List scopes = [
'email',
'https://www.googleapis.com/auth/youtube', // Youtube scope
];
final FirebaseAuth auth = FirebaseAuth.instance;
GoogleSignIn googleSignIn = GoogleSignIn(
scopes: scopes,
);
Future login() async {
final GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
final GoogleSignInAuthentication googleSignInAuthentication = await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
// You'll need this token to call the Youtube API. It expires every 30 minutes.
final token = googleSignInAuthentication.accessToken;
final AuthResult authResult = await auth.signInWithCredential(credential);
final FirebaseUser user = authResult.user;
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
final FirebaseUser currentUser = await auth.currentUser();
assert(user.uid == currentUser.uid);
var client = new http.Client();
obtainAccessCredentialsViaServiceAccount(accountCredentials, scopes, client)
.then((AccessCredentials credentials) {
// Access credentials are available in [credentials].
// ...
client.close();
});
return currentUser;
}
void signOut() {
auth.signOut();
googleSignIn.disconnect();
}
Future getUser() async{
final FirebaseUser user = await auth.currentUser();
return user;
}
}
`