Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

cannot load google client calendar javascript api

Christopher August 3, 2015

I want to create events in Google calendar from a Jira issue, in javascript.
I created a plugin with a web ressource module containing javascript sample from Google to access Calendar.
The addGapi function adds the load script line in Jira head section

function addGapi(){ 
var po = document.createElement('script'); 
po.type = 'text/javascript';
po.async = true; 
po.src = 'https://apis.google.com/js/client.js?onload=checkAuth'; 
var s = document.getElementsByTagName('script')[0]; 
s.parentNode.insertBefore(po, s); 
}
function checkAuth() {
gapi.auth.authorize(
{ 'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': true }
, handleAuthResult);
}

 

The google client api (gapi) is loaded without any error (no console message).
However the api is not correctly loaded. It does not have any function available.
For example gapi.auth.authorize() return undefined function error : 


"Uncaught TypeError: Cannot read property 'authorize' of undefinedcheckAuth @ batch.js?locale=en-US&isAdmin=true:9569(anonymous function) @ client.js?onload=checkAuth:7ga @ client.js?onload=checkAuth:1v.(anonymous function).b @ client.js?onload=checkAuth:7v.(anonymous function) @ client.js?onload=checkAuth:7I.(anonymous function) @ client.js?onload=checkAuth:7(anonymous function) @ cb=gapi.loaded_0:1"

I tried to add https://apis.google.com domain to Jira whitelist, but it does not work better.

Is there something else to configure in Jira to be able to load Google javascript client API ?

Nota : the same sample code is working with a python SimpleHTTPServer.

Thank you for your help.

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Emily Hall March 3, 2017

Christophe,

I am having the same issue. I am trying to put together a simple gadget (no plugin) to pull data out of a Google sheet and display it in the dashboard container. I too have my code working via a simple python http server on my local, but cannot seem to get the gapi library to load correctly. 

Did you get this working?

Thanks,

Emily

Christopher March 3, 2017

Not yet. 

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 10, 2015

In atlassian-plugin.xml I have web-resource that points to javascripts folder rather than to script files:

<!-- web resources for calendar -->
  <web-resource key="work-calendar-resources" name="work-calendar-resources">
    <transformation extension="js">
      <transformer key="jsI18n" />
    </transformation>
    <resource type="download" name="images/" location="/images" />
    <resource type="download" name="stylesheets/" location="/stylesheets" />
    <resource type="download" name="javascripts/" location="/javascripts" />
  </web-resource>

Then in velocity page I load the script:

<script type="text/javascript" src="$req.contextPath/download/resources/$pluginKey:work-calendar-resources/javascripts/app.js?ver=$action.pluginVersion"></script>

pluginKey should be substituted by your key that you have in atlassian-plugin tag. In deepness of app.js there is a code I posted in the first answer.


I guess that separate script files in web-resource and #requireResource should work as well, at least I do not see reasons why it should not work. I went non-standard way of including javascripts since I am gluing js files on my own and do not want JIRA do to it for me in uncontrolled manner.

 

Emily Hall March 6, 2017

Hello Volodymyr, 

I am working on a very simple (I thought) solution for status update communication. I am looking to pull data from a Google Sheets into a dashboard gadget. I was hoping to use a simple gadget, but JIRA's restrictions require I build a plugin. 

Thank you so much for your example here. I am not very experienced with plugin development, but I am excited to get started. As I start trying to make my gadget work, I am hoping that you can answer a couple of questions. 

Thank you!

Emily 

0 votes
Christopher August 7, 2015

Hi Volodymyr,

 

Thank you for your answer.

However, it gives the same result than my script.

The gapi is loaded

The onload callback is called

gapi has some functions like load, loaded0, loaded1, ...

But gapi has no auth or client member.

Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2015

Christophe, I used this sample and it worked from the start: https://developers.google.com/drive/web/quickstart/js

Christopher August 10, 2015

I also started from this sample and it works in a simple python server. But it does not work from the Atlassian webressource plugin. How do you load your script in Jira ? Do you also use a web ressource plugin or another solution ?

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2015

Hi christophe,

Funny coincident: I am in a process of integrating google calendar events into my plugin https://marketplace.atlassian.com/plugins/com.jiraworkcalendar.work-calendar

Here is the code that works for me:

var head = document.head || document.getElementsByTagName('head')[0], script = document
.createElement('script');
script.setAttribute("type", "text/javascript");
script.setAttribute('src', "https://apis.google.com/js/client.js?onload=__gooleAPICallback");
head.appendChild(script);

One more thing to check is that checkAuth is called only as callback from client.js and not from other places. I had a call from $document.ready and checkAuth was called before client.js is loaded and attached.

 

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events