Trying to retrieve the Unique device ID of the Device .
Using the plugin - UniqueDeviceID
When tring to run the following code
var exec = require('cordova/exec');
module.exports = {
get: function(success, fail) {
cordova.exec(success, fail, 'UniqueDeviceID', 'get', []);
}
};
`
I am getting the following error-
"Uncaught ReferenceError: module is not defined"
This is indeed defined in cordova.js
How do i fix this issue.
Thanks in advance
The get method needs to be called in the device.ready() of the application initialization.
Placing it elsewhere lead to the above mentioned error , worked fine for me .
There is an in built function, for getting uuid:
var string = device.uuid;
Full Example:
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
var element = document.getElementById('deviceProperties');
element.innerHTML = 'Device Model: ' + device.model + '<br />' +
'Device Cordova: ' + device.cordova + '<br />' +
'Device Platform: ' + device.platform + '<br />' +
'Device UUID: ' + device.uuid + '<br />' +
'Device Version: ' + device.version + '<br />';
}
</script>
</head>
<body>
<p id="deviceProperties">Loading device properties...</p>
</body>
</html>
Kindly, visit this link:
http://docs.phonegap.com/en/3.1.0/cordova_device_device.md.html#device.uuid
See, if that helps.
I used the UniqueDeviceID Plugin from this link: https://www.npmjs.com/package/cordova-plugin-uniquedeviceid
Very simple and powerful. Tried to unistall and reinstall the app and still returned the same UUID.
Two changes I had to make to make this plugin work for me:
1. The above link mentions to add a separate line to the config.xml file. I followed the same and I was unable to build my app. I removed the line and it works fine.
2. Also add a loop for the fail case just like the success case shown, otherwise there is a runtime error.
function fail(error) {
console.log(error); };
Related
I want use the Google Sign-In integration for my website, and I followed this doc
and this code
.
Unfortunately, this doesn't work, a pop-up appears, log me in, but the informations I need by doing console.log() doesn't appear in the console.
Here is my entire code:
<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="myclientid.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
document.write('ID: ' + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
document.write("ID Token: " + id_token);
}
</script>
<script>
document.write('Hello !');
</script>
</body>
</html>
Thanks for helping
EDIT This works on Edge, but not on Google Chrome.
SOLVED I deleted all the existing creditentials and I created new one. This worked.
I am trying to integrate Google Sign In into my web app.
My page has the Google button:
ModalDialogue.cshtml:
<a class="google g-signin2" data-onsuccess="onSignIn">Sign up with Google+</a>
I'm trying to trigger that method in my js:
ModalDialogue.js:
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
}
I know that
a] the JavaScript is in the scope of the page, since my other functions - for opening and closing the dialogue - DO work.
b] the button is communicating with Google, since clicking on it DOES open the 'sign-in with Google' dialogue - and then once done - changes the button to 'Sign In' afterward.
How do I trigger the onSignIn method? Or at least how do I determine whether onsuccess is being triggered?
Oh. My bad. I hadn't noticed I had the method wrapped in a closure. Needs to be global.
For people who come to this page in the future, I had to move the function definition above the button tag. Seems like it shouldn't matter, as data-onsuccess is simply a string. It didn't throw any error messages, unfortunately.
<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
}
</script>
</body>
</html>
for for infofor info
Define the function onSignIn in script tag, which will make it available globally.
<script>
function onSignIn(googleUser) {
console.log("I am clicked");
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId());
console.log("Name: " + profile.getName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
}
</script>
To check if your function is available globally or not, call window.onSignIn() or onSignIn() from console. You should be able to call onSignIn if it is global.
The script tag can be put at the bottom inside body tag (tested with React js),
<body>
....
<script>
...
</script></body>
alternatively it can be put inside head with async or defer attribute.
This will do its magic then,
<div className="g-signin2" data-onsuccess="onSignIn"></div>
Good luck.
enable third party cookie in your browser
I'm writing a little webpage that displays some Flickr photos and also includes microformats using oomph.js. I have bit of JS and when I run the code without <script type='text/javascript' src="oomph.js"></script> the code runs fine (all my photos are loaded. However, when I add in the above script tag, my photos don't load.
Here is my broke JS (doesn't show photos):
<script type='text/javascript' src="jquery-1.6.3.min.js"></script>
<script type='text/javascript' src="oomph.js"></script>
<script>
$(document).ready(function() {
var ajaxURL="http://api.flickr.com/services/feeds/groups_pool.gne?id=626753#N20&lang=en-us&format=json&jsoncallback=?";
$.getJSON(ajaxURL,function(data) {
$('h1').text(data.title);
$.each(data.items,function(i,photo) {
var photoHTML = '<span class="image">';
photoHTML += '<a href="' + photo.link + '">';
photoHTML += '<img src="' + photo.media.m.replace('_m','_s') + '"></a>';
$('#photos').append(photoHTML);
}); // end each
}); // end get JSON
}); // end ready
</script>
and here is the code that works (shows photos):
<script type='text/javascript' src="jquery-1.6.3.min.js"></script>
<script>
$(document).ready(function() {
var ajaxURL="http://api.flickr.com/services/feeds/groups_pool.gne?id=626753#N20&lang=en-us&format=json&jsoncallback=?";
$.getJSON(ajaxURL,function(data) {
$('h1').text(data.title);
$.each(data.items,function(i,photo) {
var photoHTML = '<span class="image">';
photoHTML += '<a href="' + photo.link + '">';
photoHTML += '<img src="' + photo.media.m.replace('_m','_s') + '"></a>';
$('#photos').append(photoHTML);
}); // end each
}); // end get JSON
}); // end ready
</script>
I've browsed the internet and have yet to find a solution. If anyone could shed some light on this issue I would greatly appreciate it :-).
I was able to fix the issue by including an older version of JQuery (version 1.3.2)
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
</head>
<body>
<div id="div1">dv1</div>
<div id="div2">dv2</div>
<script type="text/javascript">
function getData(){
$.ajax({
type:"GET",
url:"j.json",
dataType:"json",
success: function(jsondata){
output(jsondata);
}
});
}
function output(json){
//var Data = eval('(' + json + ')');
var html = '';
//alert(Data.length);
for(var i=0;i<json.length;i++){
html += ' name:' + json[i].name + ' age:' + json[i].age;
}
document.getElementById('div1').innerHTML = html;
document.getElementById('div2').innerHTML = json[0].name;
}
setTimeout(getData, 3000);
</script>
</body>
</html>
j.json file is
[{"name":"aaa","age":18},{"name":"bbb","age":19}]
The aim of above code is to update div content with data in local json file. I've tried that in IE & Chrome, but neither worked. I've googled a lot but still can't figure it out.
Anyone got any hints? Thanks in advance.
Do you use web server?
AJAX calls doesnt work with URL starting with file://. This because of the same-origin requirements which were instituted to help deal with cross-site scripting (XSS). See here for more details.
And as I noticed, you should use $(document).ready(function(){ your code }) instead of setTimeout(getData, 3000);
I'm trying to use geolocation using PhoneGap API doc, geolocation works on the index.html
but when I try to use the same function in a different page it doesn't work.
http://docs.phonegap.com/en/1.8.1/cordova_geolocation_geolocation.md.html#Geolocation
This is the JS I'm using.
This is the button I'm using to get to the other page.
I'm also using jQuery Mobile.
Add category</li>
here is the head of test.html
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
<link rel="stylesheet" href="styles/jquery.mobile-1.1.0.min.css" />
<link rel="stylesheet" href="styles/jquery.mobile.structure-1.1.0.min.css" />
<link rel="stylesheet" href="styles/jquery.mobile.theme-1.1.0.min.css" />
<link rel="stylesheet" href="styles/my.css" />
<script src="scripts/jquery-1.7.2.min.js"></script>
<script src="scripts/jquery.mobile-1.1.0.min.js"></script>
<script src="scripts/cordova-1.8.1.js"></script>
<script>
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
var watchID = null;
// Cordova is ready
//
function onDeviceReady() {
// Throw an error if no update is received every 30 seconds
var options = { timeout: 10000 };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'<hr />' + element.innerHTML;
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
First give permissions in Android Manifest:
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_COARSE_LOCATION
then copy your cordova-1.8.1.js and create index.html inside www subfolder of assets and after that copy cordova-1.8.1.jar to libs and then configure build path with cordova-1.8.1.jar.
then create res-->xml and copy plugins(from earlier downloaded PhoneGap 1.8.1).
then run the application. Definitely you will get the output.
The problem was I didn't load the cordova.jar file to my project and that's why it didn't work