bulma css
parent
42e8976ce8
commit
9069382df0
@ -1,151 +1,22 @@
|
|||||||
<html><head><title>Google APIs - Sample JS Page</title></head>
|
<!DOCTYPE html>
|
||||||
<body>
|
<html>
|
||||||
|
<head>
|
||||||
<script>
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
/***** START BOILERPLATE CODE: Load client library, authorize user. *****/
|
<title>Hello Bulma!</title>
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
|
||||||
// Global variables for GoogleAuth object, auth status.
|
<script defer src="https://use.fontawesome.com/releases/v5.0.7/js/all.js"></script>
|
||||||
var GoogleAuth;
|
</head>
|
||||||
|
<body>
|
||||||
/**
|
<section class="section">
|
||||||
* Load the API's client and auth2 modules.
|
<div class="container">
|
||||||
* Call the initClient function after the modules load.
|
<h1 class="title">
|
||||||
*/
|
Hello World
|
||||||
function handleClientLoad() {
|
</h1>
|
||||||
gapi.load('client:auth2', initClient);
|
<p class="subtitle">
|
||||||
}
|
My first website with <strong>Bulma</strong>!
|
||||||
|
</p>
|
||||||
function initClient() {
|
</div>
|
||||||
// Initialize the gapi.client object, which app uses to make API requests.
|
</section>
|
||||||
// Get API key and client ID from API Console.
|
</body>
|
||||||
// 'scope' field specifies space-delimited list of access scopes
|
</html>
|
||||||
|
|
||||||
gapi.client.init({
|
|
||||||
'clientId': '609507875704-ebiu4h3hcjdtbvcqvagu5ejjo2h0ma6n.apps.googleusercontent.com',
|
|
||||||
'discoveryDocs': ['https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest'],
|
|
||||||
'scope': 'https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtubepartner'
|
|
||||||
}).then(function () {
|
|
||||||
GoogleAuth = gapi.auth2.getAuthInstance();
|
|
||||||
|
|
||||||
// Listen for sign-in state changes.
|
|
||||||
GoogleAuth.isSignedIn.listen(updateSigninStatus);
|
|
||||||
|
|
||||||
// Handle initial sign-in state. (Determine if user is already signed in.)
|
|
||||||
setSigninStatus();
|
|
||||||
|
|
||||||
// Call handleAuthClick function when user clicks on "Authorize" button.
|
|
||||||
$('#execute-request-button').click(function() {
|
|
||||||
handleAuthClick(event);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleAuthClick(event) {
|
|
||||||
// Sign user in after click on auth button.
|
|
||||||
GoogleAuth.signIn();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setSigninStatus() {
|
|
||||||
var user = GoogleAuth.currentUser.get();
|
|
||||||
isAuthorized = user.hasGrantedScopes('https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtubepartner');
|
|
||||||
// Toggle button text and displayed statement based on current auth status.
|
|
||||||
if (isAuthorized) {
|
|
||||||
defineRequest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateSigninStatus(isSignedIn) {
|
|
||||||
setSigninStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
function createResource(properties) {
|
|
||||||
var resource = {};
|
|
||||||
var normalizedProps = properties;
|
|
||||||
for (var p in properties) {
|
|
||||||
var value = properties[p];
|
|
||||||
if (p && p.substr(-2, 2) == '[]') {
|
|
||||||
var adjustedName = p.replace('[]', '');
|
|
||||||
if (value) {
|
|
||||||
normalizedProps[adjustedName] = value.split(',');
|
|
||||||
}
|
|
||||||
delete normalizedProps[p];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (var p in normalizedProps) {
|
|
||||||
// Leave properties that don't have values out of inserted resource.
|
|
||||||
if (normalizedProps.hasOwnProperty(p) && normalizedProps[p]) {
|
|
||||||
var propArray = p.split('.');
|
|
||||||
var ref = resource;
|
|
||||||
for (var pa = 0; pa < propArray.length; pa++) {
|
|
||||||
var key = propArray[pa];
|
|
||||||
if (pa == propArray.length - 1) {
|
|
||||||
ref[key] = normalizedProps[p];
|
|
||||||
} else {
|
|
||||||
ref = ref[key] = ref[key] || {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeEmptyParams(params) {
|
|
||||||
for (var p in params) {
|
|
||||||
if (!params[p] || params[p] == 'undefined') {
|
|
||||||
delete params[p];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
function executeRequest(request) {
|
|
||||||
request.execute(function(response) {
|
|
||||||
console.log(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildApiRequest(requestMethod, path, params, properties) {
|
|
||||||
params = removeEmptyParams(params);
|
|
||||||
var request;
|
|
||||||
if (properties) {
|
|
||||||
var resource = createResource(properties);
|
|
||||||
request = gapi.client.request({
|
|
||||||
'body': resource,
|
|
||||||
'method': requestMethod,
|
|
||||||
'path': path,
|
|
||||||
'params': params
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
request = gapi.client.request({
|
|
||||||
'method': requestMethod,
|
|
||||||
'path': path,
|
|
||||||
'params': params
|
|
||||||
});
|
|
||||||
}
|
|
||||||
executeRequest(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***** END BOILERPLATE CODE *****/
|
|
||||||
|
|
||||||
|
|
||||||
function defineRequest() {
|
|
||||||
// See full sample for buildApiRequest() code, which is not
|
|
||||||
// specific to a particular API or API method.
|
|
||||||
|
|
||||||
buildApiRequest('GET',
|
|
||||||
'/youtube/v3/videos',
|
|
||||||
{'id': 'Ks-_Mh1QhMc',
|
|
||||||
'part': 'snippet,contentDetails,statistics'});
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<button id="execute-request-button">Authorize</button>
|
|
||||||
|
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
|
||||||
<script async defer src="https://apis.google.com/js/api.js"
|
|
||||||
onload="this.onload=function(){};handleClientLoad()"
|
|
||||||
onreadystatechange="if (this.readyState === 'complete') this.onload()">
|
|
||||||
</script>
|
|
||||||
</body></html>
|
|
||||||
|
Loading…
Reference in New Issue