Skip to content

Latest commit

 

History

History
60 lines (45 loc) · 1.63 KB

google_plus_platform_api.md

File metadata and controls

60 lines (45 loc) · 1.63 KB
title contributors
Google+ Platform/Sign-In
user name
shaneog
Shane O'Grady

Google+ Platform/Sign-In

developers.google.com/+/web/signin/

Official Implementation

Set configuration using page-level configuration options, and include the script in the page head.

<head>
  <script src="https://apis.google.com/js/client:platform.js" async defer></script>
</head>

Solution

Remove the script from the head and load the following script inside the <head>.

google_frame = null
google_events_bound = false

$ ->
  unless google_events_bound
    loadGoogleSDK()
    bindGoogleEvents()
    google_events_bound = true

bindGoogleEvents = ->
  $(document)
    .on('page:fetch', saveGoogleFrame)
    .on('page:change', restoreGoogleFrame)

saveGoogleFrame = ->
  google_frame = $('iframe[id^="oauth2relay"]').detach()

restoreGoogleFrame = ->
  if $('iframe[id^="oauth2relay"]').length > 0
    $('iframe[id^="oauth2relay"]').replaceWith google_frame
  else
    $('body').append google_frame

loadGoogleSDK = ->
  # We load the platform script directly and load the 
  # client library in the callback
  $.getScript('//apis.google.com/js/platform.js', initializeGoogleSDK)

initializeGoogleSDK = ->
  # You can load more libraries here depending on the platform features you want
  window.gapi.load('client', 'v1') if window.gapi

I have implemented this specifically for Google+ Sign-In via JavaScript, but this method should also work for other Google+ Platform API libraries