2014-08-29 1 views
1

지역 Hubot ("Sparky")는 많은 플러그인 스크립트를 실행하며 일반적으로 잘 작동합니다. 필자는 야후 파이프 (Yahoo Pipes)에 전화를 걸고 그 결과 JSONP를 기다리고있는 플러그인 스크립트를 작성하고있다. 그러나 _callback 매개 변수에 대해 무엇을 사용해야할지 확신 할 수 없습니다. 코드 :이 가도록노드의 커피점에서 만든 GET 요청에 대한 콜백 지정

module.exports = (robot) -> 
    robot.hear /\bkeyword\b/i, (msg) -> 
    robot.http("http://pipes.yahoo.com/pipes/pipe.run") 
     .query({ 
     _id: "legit-pipe-id-is-here", 
     _render: "json", 
     _callback: "?" 
     }) 
     .get() (err, res, body) -> 
     if body? 
      data = JSON.parse(body) 

오류 : 나는 파이프가 jQuery의 AJAX 기능을 사용하지만,이 경우에 jQuery를 자체 콜백을 설정할 때 올바르게 작동하는지 확인한

undefined:1 
_({"count":10,"value":{"title":"correct title","description":"Pipes Output","lin 
^ 
SyntaxError: Unexpected token _ 
    at Object.parse (native) 
    at e:\node\sparky\scripts\plugin-name.coffee:26:11, <js>:11:23 
    at IncomingMessage.<anonymous> (e:\node\sparky\node_modules\hubot\node_modules\scoped-http-client\lib\index.js:70:20) 
    at IncomingMessage.EventEmitter.emit (events.js:117:20) 
    at _stream_readable.js:920:16 
    at process._tickCallback (node.js:415:13) 

.

+0

@LeonidBeschastny 흠, 내가 (나를 위해 작동) 유튜브의 하나에 내 스크립트를 내놓고되었습니다 https://github.com/ github/hubot/blob/master/src/scripts/youtube.coffee # L16 – travis

답변

2

방금 ​​JSONP를 사용할 필요가 없다는 것을 깨달았 기 때문에 _callback 매개 변수가 필요하지 않습니다. 브라우저에서 없을 때 정기적 인 JSON은 대만족, 잘 작동 :

module.exports = (robot) -> 
    robot.hear /\bkeyword\b/i, (msg) -> 
    robot.http("http://pipes.yahoo.com/pipes/pipe.run") 
     .query({ 
     _id: "legit-pipe-id-is-here", 
     _render: "json" 
     }) 
     .get() (err, res, body) -> 
     if body? 
      data = JSON.parse(body) 
관련 문제