Question

I am attempting to return some json data from the vimeo API in meteor and having some trouble with callbacks and server vs client stuff this is my following code, but it is not working because it can see the http request that's in a variable on the server side in client but if I put it in the client I get a blocking error

if (Meteor.isServer) {
  var auth_url='http://vimeo.com/api/v2/video/92861889.json';
}

 //invoke the server method
 if (Meteor.isClient) {
   result = Meteor.http.call("GET", auth_url);
    var issue = JSON.parse(result.content);
    console.log(issue);
 }

Update: Current Error

     Uncaught SyntaxError: Unexpected token < test.js?6011fceba7e0032b9fbc7fe1cec33965967603ed:24
(anonymous function) test.js?6011fceba7e0032b9fbc7fe1cec33965967603ed:24
(anonymous function) httpcall_client.js:63
(anonymous function) underscore.js:750
xhr.onreadystatechange

New Code

Ok so I retyped all the code, The issue was a invisible character from copying and pasting, from what I could tell. However Than I got a cross origin error, so I did some more research and found this is the proper way to do the callback. However I am getting a error "cannot read property "content" of undefined" Some More help would be greatly appreciated. I chose a different url for the json just for testing purposes.

if (Meteor.isServer) {
  Meteor.startup(function () {

    Meteor.methods({
      'remoteGet' : function(url, options){
        return HTTP.get(url,options);
      }
    });

  });
}

if (Meteor.isClient) {

  Meteor.call('remoteGet', 'http://www.kimonolabs.com/api/ahd8tq6q?apikey=6c55fc2ded8114a1c08b8a914851de84',{

  },function(error,response){

    var issue = JSON.parse(response.content);
    console.log(issue);
});

}
Was it helpful?

Solution

On the client async operations cannot be written in a sync style. Callback is required:

 if (Meteor.isClient) {
   result = Meteor.http.call("GET", auth_url, function (err, result) {
     var issue = JSON.parse(result.content);
     console.log(issue);
   });
 }

OTHER TIPS

Seems like Vimeo updated this Json data feed so it has to be :

https://vimeo.com/api/oembed.json?url=https://vimeo.com/{VIMEOID}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top