www.webdeveloper.com
Results 1 to 2 of 2

Thread: Issues with YQL, RSS, JSON and Javascript - Please Advise!

  1. #1
    Join Date
    Jul 2013
    Posts
    1

    Issues with YQL, RSS, JSON and Javascript - Please Advise!

    Hi all,

    I have three very concrete questions about web development that I am experiencing trouble with :

    Issue #1 : Trouble accessing google.news feed .-

    I am trying to retrieve news headlines from google.news using the city and state with the following format :

    http://news.google.com/news/search?geo=Cambridge%2C+MA

    To circumvent same origin policies, I am using the YQL console http://developer.yahoo.com/yql/console/ in the following way :

    select * from rss where url = 'http://news.google.com/news/search?geo=Cambridge%2C+MA&output=rss'

    the console is configured to output JSON, cbfunc with the Diagnostics flag set

    I then extract the following YQL REST QUERY for use with Javascript :

    http://query.yahooapis.com/v1/public...26output%3Drss'
    &format=json&diagnostics=true&callback=cbfunc

    You can type this URL into your browser and you will see the news headline feed - EVERYTHING SO FAR WORKS GREAT

    When I try to use this URL within my Javascript code nothing comes back - HOW STRANGE, WHY IS THAT?

    Here is the Javascript code I am using to retrieve the data :

    var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%20%3D%20'http%3A%2F%2Fnews.google.com%2Fnews%2Fsearch%3F geo%3DCambridge%252C%2BMA%26output%3Drss'
    &format=json&diagnostics=true"&callback=cbfunc;

    $.getJSON(url, function(data) {

    if (data.status === "ZERO RESULTS") {
    alert('ERROR : City and/or State not Found! Please try again...');
    return;
    }

    var headlines = data.query.results.item;

    for (var i = 0; i < headlines.length; i++) {
    var hl = headlines[i];

    var news_title = (hl.title);
    var news_link = (hl.link);
    $("#news-content").append(news_title + '<br>');
    $("#news-content").append("<a href=" + news_link + ">Click to view this article</a>" + '<br>' + '<br>');

    }

    return false;
    });
    });

    Issue #2 : Trouble accessing weather information from Forecast.io .-

    I am using https://developer.forecast.io to retrieve weather information for my application. I am using an APIKey generated by them to do so in the following format :

    https://api.forecast.io/forecast/41d....8267,-122.423

    As before, to avoid same origin policies I am using the YQL console using this command :

    select * from json where url = 'https://api.forecast.io/forecast/41d6f087356062dd3c456c2f175cea84/37.8267,-122.423'

    This produces the following YQL url :

    http://query.yahooapis.com/v1/public...allback=cbfunc

    If you type this url into your browser it will retrieve the desired weather data - EVERYTHING UP TO HERE IS OK

    Once again when I use the url within the following Javascript code, NOTHING HAPPENS, WHY? PLEASE ADVISE

    var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%20%3D%20'https%3A%2F%2Fapi.forecast.io%2Fforecast%2F41d 6f087356062dd3c456c2f175cea84%2F37.8267%2C-122.423'&format=json&diagnostics=true&callback=cbfunc";

    $.getJSON(url, function(data) {

    if (data.status === "ZERO RESULTS") {
    alert('ERROR : ZipCode not Found! Please try again...');
    return;
    }

    Issue #3 : Converting zipcode and city + state info into latitude and longitude coordinates .-

    How can I go about converting a user provided zipcode or city + state, into it's corresponding latitude and longitude coordinates?

    ANY HELP WOULD BE GREATLY APPRECIATED, THANX IN ADVANCE

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    you have a quote in the url, chopping off the callback name, so the remote script never invokes your callback...
    alos, if using jQuery getJSON, you don't specifiy the callback yourself, jquery appends it to the back of the url.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles