How to perform query string based API call in angular JS - javascript

I am very new to angualr js. I have found a very useful article about how to connect to API and use their information to show into our app using angular JS.
http://austinknight.net/weather-app-with-angular-js/
Only limitation is this weather forecast for US only. I can find many API which provided world wide forecast but I can't connect with them the way author has done here.
$http.get('https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20weather.forecast%20WHERE%20location%3D%22' + zip + '%22&format=json&diagnostics=true&callback=')
Can someone please help me to write up such a query string based API call for any country ?
I have done sufficient research but couldn't find anything similar.
Please help.

You can pass params like this
$http.get('https://query.yahooapis.com/v1/public/yql', {
params: {
q: 'your query',
format: 'json',
diagnostics: true,
callback: ''
}
});

Related

Google Knowledge Graph API does not return results

I want to display results pulled using Google Knowledge Graph API by using the javascript code provided by the official documentation on my HTML file. Refer here:
var service_url = 'https://kgsearch.googleapis.com/v1/entities:search';
var params = {
'query': 'united_kingdom',
'limit': 10,
'indent': true,
'key': '(myapikey)',
};
$.getJSON(service_url + '?callback=?', params, function(response) {
$.each(response.itemListElement, function(i, element) {
$('<div>', {text:element['result']['name']}).appendTo(document.body);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Why isn't it returning any result? I inspected it and saw that there is a javascript error (undefined).
I think that your script is correct. In my environment, your script worked. So can you confirm the following points?
Confirm whether Knowledge Graph Search API is enabled at the project that you have the API key?
You can see it at here.
Confirm whether the API is correct.
If this was not useful for you, I'm sorry.

Swagger UI with digest authentication

I'm using Swagger to produce the documentation of my REST API. According to what is written around, the Swagger UI does not offer support for basic authentication (differently from the online editor). My problem is that one of my APIs is a POST that require digest (not even basic) authentication.
A possible solution I found around is to add a fixed user:pass authentication header in the request via javascript code. This should be easily done according to the Swagger UI documentation (see Custom Header Parameters). I report the incriminated code line:
swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", "XXXX", "header"));
Unfortunately it doesn't work. The swaggerUi.api field results uninitialised (null) after I initialise the SwaggerUi object, and as a consequence swaggerUi.api.clientAuthorizationsis undefined. I tried initialising such fields in different way, failing every time. I tried also similar calls to the API I found in threads discussing this topic, but none of them has worked. Does anyone have an idea about that? The documentation is not particularly clear about that.
For completeness, I report the js snippet where I initialise the Swagger UI
var urlPush = "./doc_push.yaml";
window.swaggerUiPush = new SwaggerUi({
url: urlPush,
dom_id: "swagger-ui-container-push",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onFailure: function(data) {
log("Unable to Load SwaggerUI");
},
docExpansion: "list",
jsonEditor: false,
defaultModelRendering: 'model',
showRequestHeaders: false,
});
Try using SwaggerClient.PasswordAuthorization instead of SwaggerClient.ApiKeyAuthorization -
var username = $('#input_username').val();
var password = $('#input_password').val();
var basicAuth = new SwaggerClient.PasswordAuthorization('basic', username, password);
window.swaggerUi.api.clientAuthorizations.add("basicAuth", basicAuth);

Slack API (JSON Data)

I'm trying to use this method provided via the Slack API to grab the "name" attribute of the "user" object and the code I'm using to do that is as follows:
controller.hears(['users'], 'direct_message, direct_mention, mention', function(bot, message){
bot.api.users.info({}), function(err, response) {
bot.reply(message, response);
var slack_username = message["user"][2];
console.log(">>>>> " + slack_username);
});
});
I'm not sure what I'm doing wrong/missing and any help would be greatly appreciated! Thanks in advance!
EDIT:
Expected Output: "dkulas"
Terminal Output" "U"
debug: Got response null {"OK":false,"error":"user_not_found"}
degub: SAY { ok: false, error: 'user_not_found', channel" 'D0UV5S7MZ' }
The Slack API method users.info requires you to provide the Slack User ID in the query. The format is U12345678. (also see here for the usage documentation)
If you want to get the user info for a user by name, use the API method users.list to get the list of all users including name and user ID and then search that list for the right match. users.list provides all information about a user, so you don't need to call user.info.
See here for the documentation on this method.

how to create autocomplete from google.maps.places.autocomplete in ExtJS

Please correct me if I'm wrong...
I write a code with no errors, in before edit this post.
but after i read a comment about how to create a Minimal, Complete, and Verifiable example. I'm very confuse, because my minimal script before didn't work, i cann't include complete code, because my complex code, and I don't have verifiable example.
I just need to know how to create autocomplete from google.maps.places to autocomplete my textfield in EXTJS.
Thanks before..
I've solved this question from #Rob Schmuecker answers.
So, the focus of this question about using an appropriate proxy to call the json from google like using :
addressModel.getProxy().setExtraParam('url', 'http://maps.google.com/maps/api/geocode/json?address=' + queryString + '&sensor=false');
to set the params dynamically, from this data model :
addressModel = Ext.define("Addresses", {
extend: 'Ext.data.Model',
proxy: {
type: 'jsonp',
url: 'https://jsonp.nodejitsu.com',
reader: {
type: 'json',
root: 'results',
totalProperty: 'totalCount'
}
},
fields: ['formatted_address']
});
after that you can create a combobox and add listener to the combobox each keyup to call the extraparam in your proxy.
this is the demo from #Rob Schmuecker :
https://fiddle.sencha.com/#fiddle/g70
and this is for the complete answer from Rob, who solved my problem :
Check This...
I've figured out a way to solve this using the Google Places-Library.
My Solution using Ext JS 3.4
1) Integrate the Google Places API
2) Create a custom Proxy (I've had extended the Ext.data.DataProxy)
2a) Set the proxy api (read: true)
2b) override the doRequest method. there you can make the calls to i.e. google.maps.PlacesService.textSearch
2c) Handle the Places Request using a Reader (I've created my custom reader)
3) store your data in a store (I've created my custom store)
4) create component that consumes data from the store
Be aware that your application has to comply to the Google Maps/Google Earth APIs Terms of Service! (You Have to show the logos, third party right holders, ect.)
There you have it!

Reddit Api Error trying to get reddit self text via snoocore node.js

I'm tryng to get the self.text on a post and using this route:
reddit('/r/Denmark/comments/2jc5yk/how_to_live_in_denmark.json').listing({
context: 1,
limit: 10,
sort: 'hot',
})
.then(function(result) {
console.log(result);
});
I have also tried using .get(), without .json and without /how_to_live_in_denmark but still the same error.
When I input the route in my browser, I get the desired JSON.
The error i get:
Uncaught Error: Invalid path provided! This endpoint does not exist. Make sure that your call matches the routes that are defined in Reddit's API documentation
What am i doing wrong?
Update: 2015-02-09
Snoocore now accepts URLS's with embedded values and does not require placeholders if you do not wish to use them.
I'm the creator of this API wrapper. I'll have to monitor StackOverflow a little bit more to catch these quicker. Feel free to open new issues on GitHub as well when you get stuck on something for a quicker response!
It looks like you are trying to call this endpoint:
GET /r/[subreddit]/comments/article
Basically anything that is in brackets is optional in Snoocore, and anything in italics is an URL parameter that you will need to define placeholders for in the call (using $parameter). More information on this can be read in the documentation (feel free to ask questions or improve upon the documentation if it isn't clear!)
So in your case, you will want to do this:
reddit('/r/$subreddit/comments/$article').get({
$subreddit: 'Denmark',
$article: '2jc5yk',
context: 1,
limit: 10,
sort: 'hot'
}).done(function(result) {
console.log(result);
});
Note that instead of defining the url parameters in the call, the are now referenced by $subreddit and $article respectivly.
Note that comments are not a listing, and therefore can't use the listings interface as you tried to do in your question.

Categories

Resources