javascript - Consume Google Feed API with Phantomjs -


i trying translate this example of google feeds api work phantomjs. following example phantomjs have following:

var page = require('webpage').create();  page.onconsolemessage = function(msg) {     console.log(msg); };  // our callback function, when feed loaded. function feedloaded(result) {   if (!result.error) {     // loop through feeds, putting titles onto page.     // check out result object list of properties returned in each entry.     // http://code.google.com/apis/ajaxfeeds/documentation/reference.html#json     (var = 0; < result.feed.entries.length; i++) {       var entry = result.feed.entries[i];       console.log(entry.title);     }   } }   page.includejs("http://www.google.com/jsapi?key=aizasya5m1nc8ws2bbmprwku5gfradvd_hgq6g0", function() {     google.load("feeds", "1");     var feed = new google.feeds.feed("http://www.digg.com/rss/index.xml");     feed.includehistoricalentries(); // tell api want have old entries     feed.setnumentries(250); // want maximum of 250 entries, if exist      // calling load sends request off.  requires callback function.     feed.load(feedloaded);  phantom.exit(); }); 

the output says:

referenceerror: can't find variable: google 

i have tried defining var google; right after include no luck. new phantomjs , js in general. pointers appreciated.

so, there issue in way using callback "includejs".

that function assuming executed in context of page: it's not. it's executed in main context.

you have injected library in page: fine. now, suppose, want "stuff" within page. have use function:

page.evaluate(function, arg1, arg2, ...); 

also, see want receive result of:

feed.load() 

in callback. fine, need bridge gap: callback in page context can't called in phantom context (yet!). need read bit doc , see how want come solution.

bare in mind: calls to

page.evaluate() 

can return json , other js simple types (strings, numbers, booleans): should "door".


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -