Last active
September 2, 2018 18:03
-
-
Save uruly/762dac308e2b90524466d4fb8c1ddbfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Google API Login | |
function youtubeLogin() { | |
gapi.load('client:auth2', () => { | |
gapi.client.init({ | |
apiKey: config.apiKey, | |
clientId: config.clientId, | |
discoveryDocs: config.discoveryDocs, | |
scope: config.scopes.join(' '), | |
}).then(() => { | |
gapi.client.load('youtube', 'v3', () => { | |
if (gapi.auth2.getAuthInstance().isSignedIn.get()) { | |
// サインイン済みなら | |
getChannelID() | |
var usr = gapi.auth2.getAuthInstance().currentUser.get(); | |
var token = usr.getAuthResponse().id_token; | |
firebaseLogin(token); | |
} else { | |
gapi.auth2.getAuthInstance().signIn().then(() => { | |
// サインインする | |
getChannelID() | |
var usr = gapi.auth2.getAuthInstance().currentUser.get(); | |
var token = usr.getAuthResponse().id_token; | |
firebaseLogin(token); | |
}).catch(error => { console.log(error) }) | |
} | |
}) | |
}).catch(function(error) { | |
console.log(error); | |
alert(error.message); | |
}); | |
}) | |
} | |
// Firebase Login | |
function firebaseLogin(token) { | |
var creds = firebase.auth.GoogleAuthProvider.credential(token); | |
firebase.auth().signInAndRetrieveDataWithCredential(creds).then((result) => { | |
if (result) { | |
let user = result.user; | |
console.log(user); | |
// ログインできたのでどっかに遷移するとか | |
} | |
}).catch (error => { | |
console.log(error); | |
}) | |
} | |
// Get YouTube ChannelID | |
function getChannelID() { | |
var request = gapi.client.youtube.channels.list({ | |
mine: true, | |
part: 'contentDetails' | |
}); | |
request.execute(response => { | |
playlistId = response.result.items[0].id; | |
console.log(playlistId); // これがチャンネルIDだああああああああああ | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment