Get WOEID from city name? - javascript

I was using Google Weather API to fetch weather info, but apparently Google had stopped its service. And I am trying to switch to Yahoo Weather API now.
var WOEID = 2502265; //random WOEID
$.ajax({
url: "http://weather.yahooapis.com/forecastjson?w=" + WOEID + "&u=c",
dataType: 'json',
success: function(data) {
console.log(data);
}
});
However, is there a way that I can get the WOEID by JavaScript only? Because back then I can just do
http://www.google.com/ig/api?hl=en&weather=NYC
and that's it.
It says on the Yahoo weather API page,
To find your WOEID, browse or search for your city from the Weather home page. The WOEID is in the URL for the forecast page for that city. You can also get the WOEID by entering your zip code on the home page.
But I want to get it by JavaScript, not manually go to weather.yahoo.com and find out the WOEID.
Don't care about the Cross-Origin Policy because I am using it in an Chrome extension and it does not apply.

Okay I got to know from your comments what exactly you want
You have a place name and you want to get the WOEID of that place name using javascript ajax calls
The url to get that is not defined any where you have to use GeoPlanet service to resolve a place to a WOEID
http://where.yahooapis.com/v1/places.q('Place name')?appid=[yourappidhere]
OR you have to use Direct YQL some what like this ( use percent encoding in the url for your city name ) appropriately and try doing an ajax call to this
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22Place%20name%22&format=xml

you can get it from yahoo too http://developer.yahoo.com/geo/geoplanet/guide/concepts.html
API Reference

DECEMBER 2018 UPDATE:
Definitely use the Direct YQL technique mentioned above by #aravind.udayashankara. I messed around with the yboss api for awhile only to see it has been discontinued (https://developer.yahoo.com/boss/search/) even though Yahoo still has plenty of documentation on it online.
Try the following instead (it runs off the page but there is code within the URL).
yourLocation = "location" (zip, city name, etc.)
urlQuery = "https://query.yahooapis.com/v1/public/yql?q=select+*+from+geo.places+where+text%3D%22" + yourLocation + "%22&format=json"

To get the Woeid by city name
using (WebClient wc = new WebClient())
{
string results = wc.DownloadString("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22" + CityName + "%22&format=xml");
}
See this article for more details

Related

YouTube API Credentials - Uncaught TypeError: Cannot read property '0' of undefined

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.

Parse.com Cloudcode, calculate driving distance between two locations

I have a beforeSave function, and one field of the class is a GeoPoint, I want to find the driving distance between the previously available data and the about to be updated data. I understand I need to use some service like Google maps to find the driving distance. But I do not understand how to use a third party js inside the cloud code or call Google directions service with a https request from cloudcode. How do I go about this. Thanks.
The solution was to call the google maps' REST services with a api key from google projects.
This is how my code went.
var url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins="+oldLatitude+","+oldLongitude
url = url+"&destinations="+newLatitude+","+newLongitude+"&key=YOUR_API_KEY";
Parse.Cloud.httpRequest({
url: url,
}).then(function(httpResponse) {
var distance = (JSON.parse(httpResponse.text)).rows[0].elements[0].distance.value;
response.success();
}, function(err) {
console.log(err);
response.success();
});

Get Google+ shares without API key for each page?

On a search result page I would like to get the count of Google+ shares for the URL of each search result item via Ajax. I already managed to set up counting functions for Facebook and Twitter:
$.getJSON('http://urls.api.twitter.com/1/urls/count.json?url=' + url + '&callback=?', function(data){
tweets = data.count;
});
$.getJSON('https://api.facebook.com/method/links.getStats?urls='+ url+'&format=json', function(data){
fblikes = data[url].shares;
});
For Google+ I also already found a solution, but this requires the API Key for each URL. Is there any way to retrieve the Google+ count without such a key? Using it for tons of dynamically loaded search results, of course I cannot create an API key for each search result URL.
Yes, it's possible to get Google +1 counts. They are retrieved via a JSON-RPC POST call.
POST URL:
https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ
POST Body:
[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"%%URL%%","source":"widget","userId":"#viewer","groupId":"#self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]
where %%URL%% is the desired URL.
Have a look at the following:
Getting google +1 Page shares via AJAX (hidden Api)
http://www.sharedcount.com/documentation.php

Use YQL to search EDGAR company filing reports

I want to use YQL to retrieve all 10-Q & 10-K files from SEC EDGAR database.
After ref to the discussions [1] & [2], I bump into some problem.
It seems that YQL cannot get search results from the search engine.
However, I can directly access the filing detail page.
Here is a jsfiddle shows the problem. Although both queries return success message, the query to the search engine returns a result of empty array.
Is there any other way to get all the html addresses of the detail filing pages without querying EDGAR search engine? Thanks.
Example code by using YQL shows below:
// results page from EDGAR search engine:
// fail to get data
var queryURL = "http://www.sec.gov/cgi-bin/browse-edgar?" +
"action=getcompany&CIK=0001326801&type=10-K&dateb=&owner=exclude&count=100";
// EDGAR 10-K detail filing page:
// success to fetch by YQL
var filingURL = "http://www.sec.gov/Archives/edgar/data/1326801/" +
"000132680114000007/0001326801-14-000007-index.htm";
$.get(queryURL).then(function() {
// get successful message, but get results of empty array
})
.then(function() {
$.get(filingURL).then(function() {
// get successful message, and get results of empty array
})
} )
The /cgi-bin URL is restricted by robots.txt, so YQL will honour that and not crawl the page.
You can see this happening by enabling diagnostics for the YQL query.
Add diagnostics=true to the YQL URL, like /v1/public/yql?diagnostics=true&callback=?
Look for the diagnostics field in the results. This contains information about the query and any URLs it visited.

How to list all comments in my domain

I am using the HTML5 version of Facebook Comment in my website. I have my own Facebook APP Id.
Using Graph-API, and FQL (I think this is how to do it), I want to list all the Comments posted in my website.
Example -
Page Title1
--Comment1
--Comment2
--Comment3
Page Title2
--Comment1
--Comment2
--Comment3
Page Title3
--Comment1
--Comment2
--Comment3
etc.
Please help me out.
It is possible, in two different ways, as long as you have a fixed set of sub-pages you want to fetch comments from.
If you have a large amount of sub-pages, or a variable amount, then you don't have a good scalable solution - and many have been looking for one:
Facebook fb:comments Graph API
How to display recent comments from Facebook Comments social plugin?
Facebook FQL query to return all comments against an application
Retrieve all comments with FQL by application ID
Facebook FQL query to return all comments against an application
fql query to get comment count no longer working
http://facebook.stackoverflow.com/questions/10023179/retrieve-all-the-comments-posted-using-fql
For a Fixed set of sub-pages in your website, you can either use a batch request, or an FQL query.
Batch Request
First, you need your access token. Just enter the following as a url in a browser (credit to this website ):
https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=APP_ID&client_secret=APP_SECRET
And this is the javascript jquery code to make a batch request to fetch comments from several urls at once:
$.ajax({
url: 'https://graph.facebook.com/',
type : "POST",
data: {
access_token : 'YOUR_APP_ACCESS_TOKEN',
batch : '[ \
{"method":"GET","relative_url":"URL1"}, \
{"method":"GET","relative_url":"URL2"} \
]'
},
success: function(data) {
jdata = JSON.parse(data);
$.each(jdata, function(index,value){
jdata[index].body = JSON.parse(value.body);
console.log(value.body);
});
// Do whatever you want with jdata
}
});
FQL
inspired from this post
FB.api({
method: 'fql.query',
query: 'select text from comment where object_id in (select comments_fbid from link_stat where url="URL1" or url="URL2")'
}, function(response) {
// Do something with results
});
Conclusion
Because of this limitation of Facebook, I plan to switch to disqus.com, which apparently supports this feature (As you can see from this blog, for example. (search for 'recent comments')
Rather than list all the comments on your site, Facebook wants you to implement code to get notified when a new comment is posted anywhere on your site.
To make this happen, you have to put some Javascript into the page where the comment is posted to also notify yourself:
window.fbAsyncInit = function(){
console.log("subscribing to comment create");
FB.Event.subscribe('comment.create',function(response){
console.log("facbeook comment created: " + JSON.stringify(response));
var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
FB.Data.waitOn([commentQuery], function () {
console.log("Facebook comment: " + JSON.stringify(commentQuery));
});
});
};
Where rather than just logging the comment to the console, you would need to implement some AJAX that would send the comment back to your site where you could store the comment in your database, or send yourself an email notifying you that the comment has been posted.
Reference: Facebook Comments Plugin
Say your website is http://mywebsite.com/blog.php?id=3 and you have a facebook comments plugin on it,
you can access comments this way
https://graph.facebook.com/comments/?ids={YOUR_URL}.
{YOUR_URL} becomes http://mywebsite.com/blog.php?id=3
Example 1: (Comments plugin installed on developers facebook doc website )
website: http://developers.facebook.com/docs/reference/plugins/comments
fetch comments: https://graph.facebook.com/comments/?ids=http://developers.facebook.com/docs/reference/plugins/comments
Example 2:
website: http://techcrunch.com/2011/04/08/the-seven-most-interesting-startups-at-500-startups-demo-day/
fetch comments: https://graph.facebook.com/comments/?ids=http://techcrunch.com/2011/04/08/the-seven-most-interesting-startups-at-500-startups-demo-day/
Check this too
Sample code for pulling comments can be found on this blog post

Categories

Resources