Using Google for Easy QR Codes #edtech

Automatically add QR codes to Moodle and other PHP Content Management Systems.

qr code and short link created with google apiI’ve been using goo.gl with the google charts api in order to dynamically create reasonably sized qr codes for displaying on Moodle pages.  I’m posting the code here, most of which comes straight off google, but some of which shows how to format a possible url from Moodle and display the image.

This example is to show a QR Code and a goo.gl short code that will add the ical calendar export to display a mobile compatible HTML5 website (as image below).  Red code is mine/Moodle and Green code is Google.

$username = $USER->username;

$usernameencoded = urlencode($USER->username);

$authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);

$longUrl = $longUrl =http://learn.mysite.co.uk/mods/calendar/ical.html?address=http://learn.mysite.co.uk/calendar/export_execute.php?preset_what=all&preset_time=recentupcoming&username=’.$username.’&authtoken=’.$authtoken;

$apiKey = ‘yourapikeygoeshere’;

//Get API key from : http://code.google.com/apis/console/

$postData = array(‘longUrl’ => $longUrl, ‘key’ => $apiKey);

$jsonData = json_encode($postData);

$curlObj = curl_init();

curl_setopt($curlObj, CURLOPT_URL, ‘https://www.googleapis.com/urlshortener/v1/url’);

curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($curlObj, CURLOPT_HEADER, 0);

curl_setopt($curlObj, CURLOPT_HTTPHEADER, array(‘Content-type:application/json’));

curl_setopt($curlObj, CURLOPT_POST, 1);

curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);

$response = curl_exec($curlObj);

//change the response json string to object

$json = json_decode($response);

curl_close($curlObj);

$this->content->text .=’<div style=”text-align: center;”><div>Link to mobile calendar<br/></div><div><a href=”‘.$json->id.’” target=”_new”>’.$json->id.’</a><br/><img src=”http://chart.apis.google.com/chart?cht=qr&chld=L|0&chl=’.$json->id.’&chs=120×120″ hspace=”4″ alt=”This is a QR Code link to the calendar”></div>’;

This entry was posted in edtech, Mobile Learning, Utilities and tagged , , . Bookmark the permalink.

2 Responses to Using Google for Easy QR Codes #edtech

  1. Pingback: Using Google for Easy QR Codes | Anything and e...

  2. Pingback: Using Google for Easy QR Codes | Anything and everything about eLearning » Jewish"ed" Tech

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Please type the characters of this captcha image in the input box

Please type the characters of this captcha image in the input box

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>