Création des Logiciels de gestion d'Entreprise, Création et référencement des sites web, Réseaux et Maintenance, Conception
Création des Logiciels de gestion d'Entreprise, Création et référencement des sites web, Réseaux et Maintenance, Conception
package com.blogpost.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.visualization.client.AjaxLoader;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.Query;
import com.google.gwt.visualization.client.QueryResponse;
import com.google.gwt.visualization.client.Query.Callback;
import com.google.gwt.visualization.client.visualizations.AnnotatedTimeLine;
public class BlogPost implements EntryPoint {
public void onModuleLoad() {
AjaxLoader.loadVisualizationApi(new Runnable(){
public void run() {
Query query =
Query.create("http://spreadsheets.google.com/pub?key=pCQbetd-CptH5QNY89vLtAg");
query.send(new Callback(){
public void onResponse(QueryResponse response) {
if (response.isError()) {
Window.alert("An error occured: " + response.getDetailedMessage());
}
DataTable data = response.getDataTable();
AnnotatedTimeLine.Options options = AnnotatedTimeLine.Options.create();
options.setDisplayAnnotations(true);
RootPanel.get().add(new AnnotatedTimeLine(data, options, "800px", "400px"));
}
});
}}, AnnotatedTimeLine.PACKAGE);
}
}
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
The first part of the asynchronous tracking code snippet assigns the _gaq variable to a JavaScript array. After that, two tracking API calls (encoded as arrays) are pushed onto _gaq. When the tracking code initializes, it transforms the _gaq object from a standard array into a new object and executes all the tracking API calls initially collected in the array. With this feature, you can immediately store all necessary tracking calls even before the Google Analytics tracking code is downloaded! No more worrying about race conditions or dependency issues on the ga.js tracking code.Brendan |
Antonio |
Loading an API and making a request is as easy as executing:
<script src="https://apis.google.com/js/client.js?onload=CALLBACK"></script>
You can use the APIs Explorer to check all the methods available for an API, as well as the parameters for each method. For instance, use the above syntax with the
gapi.client.load('API_NAME', 'API_VERSION', CALLBACK);
// Returns a request object which can then be executed.
// METHOD_NAME is only available once CALLBACK runs.
var request = gapi.client.METHOD_NAME(PARAMETERS_OBJECT);
request.execute(callback);
plus.activities.search
method of the Google+ API to query activities:To try this yourself, sign up in the Google APIs console or refer to the documentation on acquiring and using a developer key in the Google+ API.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
function init() {
// Load your API key from the Developer Console
gapi.client.setApiKey('YOUR_API_KEY');
// Load the API
gapi.client.load('plus', 'v1', function() {
var request = gapi.client.plus.activities.search({
'query': 'Google+',
'orderby': 'best'
});
request.execute(function(resp) {
// Output title
var heading = document.createElement('h4');
heading.appendChild(document.createTextNode(
resp.title));
var content = document.getElementById('content');
content.appendChild(heading);
// Output content of the response
if (!resp.items) {
content.appendChild(document.createTextNode(
'No results found.'));
} else {
for (var i = 0; i < resp.items.length; i++) {
var entry = document.createElement('p');
entry.appendChild(document.createTextNode(
resp.items[i].title));
content.appendChild(entry);
}
}
});
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=init"></script>
<div id="content"></div>
</body>
</html>