I'm incredibly new to HTML/Javascript/API's and im trying to make my first chrome extension using coinmarketcaps' public API.
API: https://api.coinmarketcap.com/v2/ticker/?limit=12&sort=rank&convert=ETH
My Code:
console.log("Running");
function setup() {
loadJSON('https://api.coinmarketcap.com/v2/ticker/?
limit=12&sort=rank&convert=ETH', gotData, 'jsonp');
}
setup();
function gotData(data){
console.log(data);
list = data;
}
gotData();
Essentially what I want to do is load in the data and then print the data to my console to make sure that it is in fact loaded. The error that I'm getting when i check the background.js console after uploading the extension is 'loadJSON is not defined'
I don't know if im missing a package or am unable to use such a command but after looking online for a while I can't seem to figure it out. Another thought that I had was maybe it can't be used in a background.js file. Also, I am using Atom software for this project. Let me know if you need any more information, any help is appreciated.
Related
I'm trying to read a directory to check how many files exists
When I open the app I get this error
ionic.bundle.js:26799 TypeError: Cannot read property
'externalDataDirectory' of undefined
But when I go to another view, and came back, this works fine.
I try to call the same function on
$ionicPlatform.ready and works, but this way is executable only once, I need to call every time I enter on this page.
Anyone had this error before?
I'm using ionic v1 and $cordovaFile extension
Thank you
Wrap your code with $ionicPlatform.ready:
$scope.$on('$ionicView.enter', function() {
$ionicPlatform.ready(function() {
// cordova file code
});
});
I am trying to flash a hex file to an Arduino through a Chrome app I am making. I used basic NodeJS code, which is below, and converted it using browserify so that it would work in the browser. It doesn't work and I'm getting an error in the console saying 'TypeError: fs.readFileSync is not a function'
var Avrgirl = require('avrgirl-arduino');
var avrgirl = new Avrgirl({
board: 'uno'
});
avrgirl.flash('Blink.cpp.hex', function (error) {
if (error) {
console.error(error);
} else {
console.info('done.');
}
});
You can't run this type of code in a browser (even with browserify). You should be running it in node.js.
I would guess that your error is coming from inside of:
avrgirl.flash('Blink.cpp.hex', ...)
since you're passing a filename and that function is likely trying to read that file.
browserify cannot magically give a browser powers that it otherwise would not have such as reading files from your hard drive or communicating with arduino hardware. This code was probably meant to be run in the node.js environment.
The instructions for the avrgirl-arduino module, pretty clearly state you should be running in node.js.
I know this is quite old but: Noopkat has made an avrgirl demo that uses webserial to flash board from the browser! Check it out. https://github.com/noopkat/avrgirl-arduino/tree/master/tests/demos/webserial
The Problem
I am trying output a file from a Chrome Packaged app (using chrome.fileSystem) that I am developing, but all the files are being saved are being created, but with no content no matter what I do. I have researched this for hours and can only seem to find people using the same basic code that I am, and that I can't get to run. Am I missing something obvious here? Is this code running for everyone else, and I should just try to run it on a friends computer? Any help would be appreciated!
What I Have Done So Far:
I am using the code below (from the Chrome developer documentation) in one of my javascript files to try and write some text to a file that the user specifies. As far as I can tell, this should write "1234567890" to whichever file I specify when I run the program, but all of the files are being created properly, but they don't have any content.
chrome.fileSystem.chooseEntry({type: 'saveFile'}, function(writableFileEntry) {
writableFileEntry.createWriter(function(writer) {
writer.onerror = errorHandler;
writer.onwriteend = function(e) {
console.log('write complete');
};
writer.write(new Blob(['1234567890'], {type: 'text/plain'}));
}, errorHandler);
});
I have also set the following permissions in my manifest.json file:
"permissions": [
{"fileSystem": ["write"]}
]
Thanks in advance for all your help!
If the errorHandler function isn't defined, that could be the problem. Your code would then crash after the file was created but before the blob was written to it.
I would like to use the Parse framework directly in Google Apps Script and copied the following source code from Parse.com directly into my project.
However, it seems that there are some adjustments required to get this to work correctly. e.g. when running the following sample code...
function upload()
{
Parse.initialize("wCxiu8kyyyyyyyyyyyyyyyyy", "bTxxxxx8bxxxxxxxxx");
var TestObject = Parse.Object.extend("TestObjectJSSSSS");
var testObject = new TestObject();
testObject.save({foo: "bar"}, {
success: function(object) {
alert("yay! it worked");
}
});
}
… I get the error message TypeError: Cannot call method "getItem" of undefined.
which seems to relate to localStorage. I believe I should replace localStorage with a similar storage type available in Google Apps Script. Would that be possible and how would I need to adjust the Parse code?
What other adjustments would I need to get to the Parse framework to work in my Google Apps Script project?
I would suggest that using Parse REST API would be a far simpler solution and it is meant for such cases.
I'm trying to delete a file using the GDriva API for JavaScript. This page is quit straight forward it seems, but it doesn't work.
https://developers.google.com/drive/v2/reference/files/delete
Looks like it should be easy to do
function deleteFile(fileId) {
var request = gapi.client.drive.files.delete({
'fileId': fileId
});
request.execute(function(resp) { });
}
But I get "Uncaught TypeError: Cannot read property 'files' of undefined"
Does anyone know what's wrong? I have all permissions right. I can create and update a file but not remove it.
UPDATE!
Found this: Deleting a Google Drive file using JS client. There's seems to be a bug in the API. There's a solution which delete the document so that you can't find it with the API, using list, but the document will remain in your Google Drive and will be corrupted. You can view it but not remove or open it.
Sounds like you didn't load the drive client library. Your error message says that gapi.client.drive is undefined. You should have a line like:
gapi.client.load('drive', 'v2', function() { /* Loaded */ });
which will load the drive API and define gapi.client.drive. Make sure you either call delete in the callback, or otherwise ensure that drive is loaded before trying to delete a file.
Or, as #MasNotsram mentioned, you could just use the gapi.client.request syntax for calling delete.