Can I use angularfire2 Google firebaseauth to login to YouTube?

41 views
Skip to first unread message

Todd H

unread,
Sep 5, 2018, 4:50:04 PM9/5/18
to Firebase Google Group
In my Angular 5 / Ionic 3 project, I have Google authentication setup through firebaseauth, and it is working great. 

Is there a simple way for me to use that authentication to also access subscription videos in my Youtube account? I'm trying to avoid using the gapi youtube api, and just send auth data with my youtube request.


    constructor(public http: HttpClient, private afAuth: AngularFireAuth) {
        this.afAuth.auth.currentUser.getIdToken().then(token => this.token = token);
    }

    getSubscribedVideos() {
        return this.http.get('https://www.googleapis.com/youtube/v3/subscriptions?key=' + this.apiKey 
                + '&mine=true&part=snippet,id&maxResults=20',
                { headers: new HttpHeaders({ 'Authorization': 'Bearer ' + this.token} })})
            .map(data => data['items']);
    }

I am getting a 401 "Invalid Credentials" back from the Youtube api. What other data or headers or parameters do I need to send to the youtube api endpoint to authorize the request?

From my package.json:

    "@angular/core": "5.2.11",
    "ionic-angular": "3.9.2",
    "angularfire2": "^5.0.0-rc.11",
    "firebase": "^5.4.0",
    "rxjs": "5.5.11",

Ian Barber

unread,
Sep 13, 2018, 5:30:39 PM9/13/18
to Firebase Google Group
No - the Firebase token is not a Google Sign In access token, which is what you would need. If you're using google as a sign in provider, you should be able to get the access token using the regular google sign in client.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/e68e63b5-4ead-4860-8a2c-bff0e0648725%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages