Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include User-Agent info in a Meteor.http.call? MediaWiki requires it

Tags:

meteor

Whenever I call the below method (CoffeeScript) that is on the server I get "Scripts should use an informative User-Agent string with contact information, or they may be IP-blocked without notice" from Wikipedia. How do I include user-agent info in the call? Or does it grab this from Meteor Accounts (which I'm not using yet)? thank you for any help...

Meteor.methods
  wpSearch: (queryStr) ->
    result = Meteor.http.call "GET", "http://en.wikipedia.org/w/api.php",
      params:
        action: "query"
        list: "search"
        format: "json"
        srwhat: "text"
        srsearch: queryStr
like image 459
GaryM Avatar asked Dec 03 '12 01:12

GaryM


2 Answers

To clarify the previous answer for future visitors, the syntax for Meteor.http.get is as follows:

result = Meteor.http.get("https://api.github.com/user", {
   headers: {
      "User-Agent": "Meteor/1.0"
   },
   params: {
      access_token: accessToken
   } 
});

Note the curly braces around the headers option and the comma afterwards separating the headers and params options (it's a syntax error without these things). This is example is part of the EventedMind how-to to customize the loginButtons during the onCreateUser() callback.

like image 159
s1n Avatar answered Oct 15 '22 10:10

s1n


Just set User-Agent in the headers parameter (see http://docs.meteor.com/#meteor_http)

Meteor.methods
  wpSearch: (queryStr) ->
    result = Meteor.http.call "GET", "http://en.wikipedia.org/w/api.php",
      headers:
        "User-Agent": "Meteor/1.0"
      params:
        action: "query"
        list: "search"
        format: "json"
        srwhat: "text"
        srsearch: queryStr
like image 24
Dan Dascalescu Avatar answered Oct 15 '22 12:10

Dan Dascalescu