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.
Community moderators have prevented the ability to post new answers.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Christophe, I used this sample and it worked from the start: https://developers.google.com/drive/web/quickstart/js
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.