A) <script src="https://apis.google.com/js/api:client.js"></script>
versus
B) <script src="https://apis.google.com/js/client.js"></script>
The only differnence being the api: before client.js.
CDN A is used in the Google Sign-In for Websites docs in the Building a button with a custom graphic section.
CDN B is used almost in the Google API Client Library for JavaScript (Beta) docs.
They both appear to work interchangeably.
Short answer: there is no difference
Long answer:
The Google JS client CDN is a bit weird because the actual JS you get is dynamically created based on the file name you provide.
You can load multiple components of the library by constructing the URL as module1:module2:module3.js
api is the core part and is always loaded even if you don't add it to the list of modules, because it handles loading the other modules.
Theoretically you could just include api.js and then dynamically load extra modules by calling gapi.load("module", callback) which is exactly what happens when you load api:client.js or just client.js
If for example you would want to use the API Client Library together with the new sign-in methods you could include api:client:auth2.js or client:auth2.js.
And for extra confusion you could even include https://apis.google.com/js/.js which is the same as https://apis.google.com/js/api.js
Use links only from the documentation!
Simple to check this:
1) Add to header of your page this script:
<script src="https://apis.google.com/js/client.js"></script>
Open DevTools -> Network
I see:
2) Change link to other script
<script src="https://apis.google.com/js/api.js"></script>
Open DevTools -> Network
I see:
api.js is the core, when client.js is the module.
Here a completely different content: https://apis.google.com/js/platform.js
Related
We are in the process of implementing Sign In With Google functionality on our website. In the tutorial code snippet, external script is loaded from Google server:
<script src="https://accounts.google.com/gsi/client" async defer></script>
Is it possible to host this library locally? Where can I find all the files that I need to download?
EDIT:
I tried saving the JavaScript file content locally. However, it still tries to load the styles from the external URL (https://accounts.google.com/gsi/style). I guess I could modify the source of JavaScript source code so that it loads this CSS from my server, but it seems like an ugly solution to me. Is there any other way besides modifying their source code?
I would like to track the users on my Symfony 2.7 page using Piwik.
Piwiks default tracking option is the integration of a small JavaScript into the webpage, e.g. with the page footer. Of course this could easily be done by adding the code to the base Twig template.
However I would like to avoid the usage of JavaScript. My Symfony page and the Piwik page both run on the same server. Actually I am surprised that letting the client communicate with Piwik (over Javascript) is the recommended option instead of a direct way to let the webpage server talk to Piwik.
I think the Tracking HTTP API and the PHP Client are what I am looking for. However I am not sure on how to integrate this into Symfony.
I managed to connect my Symfony page with Piwik, however I wonder if this the right/best way to do it:
Used composer require "piwik/piwik-php-tracker" to add the PHPTracker to my Symfony project
Added a new Service that is responsible to create and manage a PiwikTracker object. The Service makes different methods of the Tracker, e.g. doTrackPageView() available to the rest of the project.
Added a new Twig function which uses the Service to trigger the doTrackPageView() method.
Added a call to this function to my base template
This works fine: Page views are correctly reported to Piwik and recorded without any problem. Of course I could easily add other methods to track events, actions, etc.
But: I am really surprised that I could not find any ready-to-use solution for this. Did I miss anything or is this the indented way to use Piwik with Symfony?
I have a Meteor webapp. (e.g. http://www.merafi.com). I want to scrape the website using Google Apps Script. I wrote a small script for this.
function myFunction() {
const url = 'http://www.merafi.com';
const response = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
return response.getContentText();
}
The script is used inside a Google Spreadsheet as a macro.
=myFunction()
The problem with scraping a Meteor webapp is that I get an empty body with only script tags within it. How do I get the content inside the body tag?
Some crawler like PhantomJS or NightmareJS is required to run the Meteor JS after the page is loaded. Unfortunately, Google Apps Script environment does not allow to load external dependencies / packages. The Apps Script API does not have any method which loads a page in a separate iframe / webview. This is not possible using Google Apps Script.
Thanks to #Floo and #CodeChimp for answering the question in comments.
Google Analytics demo code at .
Logged in to Google Chrome as the owner of the Analytics Account and then navigating to that page displays my Google analytics data correctly.
I follow instructions on the page and embed the code into a simple page .
Authentication works as indicated by the displayed message: “You are logged in as: me(at)gmail.com” but there is nothing more, no graph no message.
I am reasonably certain that the page is coded correctly as I have:
Basic Dashboard (basic.html)
Multipleviews (multipleviews.html)and
Interactive Charts (ic.html)
all working and displaying correctly (they display but not styled like the demo).
Why will the page not display the graphics?
As Eike pointed out in the comments, you've simply copied and pasted the code from the demo without downloading the components to your own server. If you open up your JavaScript console, you'll notice that you have 404 errors saying the browser can't find those components. Here's a screenshot of what I see on your site:
To add those components to your site, you have a number of options. I've answered a similar question on one of the repo's Github issues, but I'll copy it here for convenience.
The built and minified versions of those components are located in the build/javascript/embed-api/components directory. You can simply download those files and add them as script tags on your page, or include them in your site's main, bundled script.
If you're using an AMD script loader like RequireJS, you can also just point to those built files as they're wrapped in a UMD wrapper.
If you're using a tool like browserify or webpack, you can npm install this repo and require the files in the src/javascript/embed-api/components directory.
I'm Trying to make a simple web browser in node-webkit, to polyfill features that Chromium doesn't support yet (time element, etc). I have had success in listening for the iframe.onload event and then appending a script tag with the polyfills, but this still means that features that I've polyfilled won't be detected by Modernizr or other feature detention.
I've tried loading the page using the http node module, appending a script tag and then turning the page source into a data URI for the frame but data uris essentially turn external pages into static html with no scripting, which renders many web pages unusable.
Also, loading a page through node's http module is proving extremely slow compared to loading through an iframe.
So, is there any other way? Ideally I run a script in the iframe before any other scripts are run.
Yes, I am using nwfaketop and nwdisable on the iframe.
The 'document-start' event should be helpful. See https://github.com/rogerwang/node-webkit/wiki/Window#document-start
See also Window.eval() in https://github.com/rogerwang/node-webkit/wiki/Window#windowevalframe-script