I've got a Trigger.io app that queries a Parse.com app for some content in a Parse class called "Event". When I run the query (after the page loads), I receive the following error in the Trigger.io Toolkit console (generated from my javascript below):
Error: 100 XMLHttpRequest failed: {"readyState":4,"onloadstart":null,"withCredentials":false,"onerror":null,"onabort":null,"status":0,"responseXML":null,"onload":null,"onprogress":null,"upload":{"onloadstart":null,"onabort":null,"onerror":null,"onload":null,"onprogress":null},"statusText":"","responseText":""}'
Here is the javascript (in js/index.js):
// Set up for query
var Event = Parse.Object.extend("Event");
var query = new Parse.Query(Event);
query.limit(3);
// Make the query
query.find({
success: function(results) {
forge.logging.log("[getEvents] Successfully retrieved " + results.length + " events.");
// Do something with the returned Parse.Object values
},
error: function(error) {
forge.logging.log("[getEvents] Error: " + error.code + " " + error.message);
}
});
And here is the markup that calls the javascript (placed at the end of the page):
<script>
Parse.initialize("MyParseComApplicationID", "MyParseComJavascriptAPIKey");
</script>
<script type="text/javascript" src="js/index.js"></script>
I've tried lots of variations on this, but I've not been able to get past this (and I haven't seen this error here on stackoverflow or in lots of google searching).
Any thoughts are appreciated. Thanks
UPDATE: Just to clarify, the problem occurs when trying to run the app from Forge on an Android device. When I run from Forge on Web (e.g. just in a browser), I do not receive the error and I do receive data back from Parse.com.
I've tried with both the Javascript Key and the Client Key.
After receiving some guidance from Antoine and re-reading the photo demo (https://github.com/blueski/Forge-Parse-Demo/blob/master/js/parse-demo.js), I realized that I did not need to call Parse.initialize at all and instead I could use forge.request.ajax to get around the cross domain limitation.
One important item that eluded me was to use the Parse.com REST Key, not the Javascript Key when calling with forge.request.ajax
Also (really embarrassed here), it's always a good idea to confirm that wifi is actually enabled! :)
Related
I am trying to read device Id from Event Hub (on the back of IoTHub) but my syntax in JS seems wrong.
module.exports = function (context, IoTHubMessages) {
context.log(`JavaScript eventhub trigger function called for message array: ${IoTHubMessages}`);
var deviceId = IoTHubMessages.SystemProperties["iothub-connection-device-id"];
The function returns an error: Exception: TypeError: Cannot read property 'iothub-connection-device-id' of undefined
I'm not entirely sure if "iothub-connection-device-id" is the correct name of the attribute on Event Hub but the problem seems to be with SystemProperties.
Appreciate any help.
iothub-connection-device-id is the right key to use, you just have to use it on the right property bag. An unrelated GitHub issue https://github.com/Azure/azure-sdk-for-js/issues/7801 shows how this key is indeed available on each message.
Depending on the cardinality in your functions.json file, IotHubMessages will either be an array of messages or a single message. See IOTHubMessage.forEach is not a function? for more details.
If it is an array of messages, accessing SystemProperties directly on it will not work. You will need to loop through to access each message separately.
Do you see systemProperties on the individual messages? If yes, then message.systemProperties["iothub-connection-device-id"] should work.
You should be reading messages this way. Read this for more about regarding the topic - https://learn.microsoft.com/en-us/samples/azure-samples/functions-js-iot-hub-processing/processing-data-from-iot-hub-with-azure-functions/
IoTHubMessages.forEach(message => {
context.log(`Processed message: ${message}`);
count++;
totalTemperature += message.temperature;
totalHumidity += message.humidity;
deviceId = message.deviceId;
});
First, use the JSON.stringify to print you the payload received. Secondly i believe you should be able to access your device id by doing the following: message.annotations["iothub-connection-device-id"]. For more info, please reference to the Quickstart examples you have available in the Microsoft's Github repos. Navigate to the iot-hub\Quickstarts\read-d2c-messages folder and you should find the example of processing the message payload and printing the output.
I landed on this question when looking for the deviceId when a deviceTwinChange happens on on Azure Iot hub and the message it routed through event hub to my Azure function. In IotHubMessage I wave only getting reported or desired information. I was looking for the deviceId so i knew what device it came from
properties: {
reported: {
//everything in my reported section
}
}
But i found out this:
module.exports = function (context, IoTHubMessages) {
The device Id is in the context variable. I just did not on Azure Iot hub using an Azure function.
var deviceId = context.bindingData.systemProperties["iothub-connection-device-id"];
A bit annoying that the metadata is kept in context and there is no documentation about this.
Extra points: There is no application properties in the context. Does anyone know how to get application properties in the information send to the azure function? This is for when you enrich the data from azure iot hub
This is the information in azure iot hub when doing the routing. Just havent seen the information in my azure function come through.
Add up to 10 message enrichments per IoT Hub. These are added as application properties to messages sent to chosen endpoint(s).
I'm using YouTube API Browser key, I've got two keys here, one is mine that I created yesterday, the other one is from the sample project where I got the code from.
The problem is that if I use my own key, it won't work. It's only working the other key from a random user.
When I checked the console, I saw it is throwing this error:
Uncaught TypeError: Cannot read property '0' of undefined
The temp key for testing the code is this:
AIzaSyDXpwzqSs41Kp9IZj49efV3CSrVxUDAwS0
You can create your own key at:
https://console.developers.google.com/apis/credentials
My code is as follows:
Like this:
/*YouTube API V3*/
var youtube = 'CHANNEL_ID';
//YouTube API V3
$.ajax({
url: 'https://www.googleapis.com/youtube/v3/channels?part=statistics&id='+youtube,
dataType: 'jsonp',
type: 'GET',
data:{
key:'KEY_GOES_HERE'
},
success: function(data) {
var subscribers = parseInt(data.items[0].statistics.subscriberCount);
var k = kFormatter(subscribers);
$('#posts .youtube .count').append(k);
getTotal(subscribers);
}
});`
Solved.
All I had to do was using my domain name without any dots in the beginning and slashes in the end, inside the API CONSOLE, like this:
Accept requests from these HTTP referrers (web sites) (Optional) Use
asterisks for wildcards. If you leave this blank, requests will be
accepted from any referrer. Be sure to add referrers before using this
key in production.
mysitename.com
It may take a few seconds, or minutes, to take effect after saving.
In any case, just keep that field empty if the error persists.
If it works one time and the other time it doesn't, like randomly working every time you refresh the page or browse to another page, just leave the field empty, it's not hosted in your own server anyway, blame google for being irresponsible with their API.
I've constructed a course in Storyline2, and defined several triggers via javascript as xAPI (tincan) activities.
I have an LRS endpoint link and authorization token, but I'm yet to understand where these credentials should be embedded in order for the whole thing to function properly.
I was given this at another message board:
var tincan = new TinCan({url: window.location.href});
Which of these needs to be replaced by one of the above mentioned? I'm guessing another should be added via "+" after "href".
That example code (which I guess you got from the article I wrote here: http://tincanapi.com/share-statements-between-courses/ ) is envisaging that you will launch the Storyline content from something like an LMS. In that case you will enter the endpoint and authorization details in the LMS settings, and the LMS will pass those to Storyline.
See: http://tincanapi.com/share-statements-between-courses/
If you want to put the details directly in the package, see the example code here: http://rusticisoftware.github.io/TinCanJS/
(included below for convenience)
var lrs;
try {
lrs = new TinCan.LRS(
{
endpoint: "https://cloud.scorm.com/tc/public/",
username: "<Test User>",
password: "<Test Password>",
allowFail: false
}
);
}
catch (ex) {
console.log("Failed to setup LRS object: " + ex);
// TODO: do something with error, can't communicate with LRS
}
I created a custom javascript button in developer environment that has the below function to determine the amount of products attached to the Opportunity with a specific Product Name. I am getting a malformed query error from this function:
function getProductTypes (oppId) {
var result = sforce.connection.query("Select COUNT(Id) prodCount From OpportunityLineItem where OpportunityId = '" + oppId + "' and PricebookEntry.Product2.Name IN ('EAP') ");
var count = result.records.prodCount;
return count;
}
What I don't understand is that in my salesforce developer environment, this button works 100% but when I went to install this into a client's developer sandbox, it gave me the malformed query error: Aggregate query not allowed with this api version. Is there a setting that I need to change in their dev environment or is there something really wrong with my code?
Thanks!
Rachel
Check the version number in your {!REQUIRESCRIPT("/soap/ajax/(here!)/connection.js")}.
Probably it's something ancient like "13" they still have in the docs.
There's also non-zero chance that this function tries to be smart and doesn't include the connection.js if one of previous buttons has used it. Check the custom JS buttons that load before yours on your client's page layout and bump them all up?
hi i am try to integrate LinkedIn with my mobile application which is developing in phonegap with Xcode.
Now i have get the authorization using javascript library from github(https://github.com/bytespider/jsOAuth/blob/daa8823a02fa570b285ac26f66ff6c5d8be9d4ec/src/OAuth/Consumer.js)
jsoauth but i do not know how to set header for "https://api.linkedin.com/uas/oauth/accessToken" any one please give example for it.Now i got oauth_token,verifier,oath_token_secret.how can i use it? i get the problem send like
code is:
var options={
consumerKey:'XXXXXXXXXX',
consumerSecret:'XXXXXXXX',
verifier: verifier,
signatureMethod:'HMAC-SHA1'
};
oauth = OAuth(options);
oauth.post('https://api.linkedin.com/uas/oauth/accessToken', null,
function(data) {alert('acess');
window.plugins.childBrowser.close();
},
function(data) {
alert('no access');
console.log(data.error);
}
);
here the error function called and Xcode error shows like:
* WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: * -[JKArray objectAtIndex:]: index (1) beyond bounds (1)
any one help me how get the AccessToken of LinkeIn.
I don't think you can set the verifier as an option.
Try using the function
oauth.setVerifier('verifier')
&
oauth.setAccessToken('MY-ACCESS-KEY', 'MY-ACCESS-SECRET');
http://bytespider.github.io/jsOAuth/api-reference/
After that, the jsOAuth will set the headers for you.
I also just had a problem fetching the access token using this library and it turned out that it was including the callback parameter unnecessarily, which made the request fail.