Skip to content
Browse files

fixed oauth bug, added workaround

  • Loading branch information...
1 parent 0012277 commit 8af7cfe552cee884106a639323b740cee7cadcc2 @mren committed Mar 16, 2011
Showing with 20 additions and 7 deletions.
  1. +1 −1 README.md
  2. +16 −3 lib/raw.js
  3. +1 −1 lib/user.js
  4. +2 −2 package.json
View
2 README.md
@@ -33,7 +33,7 @@ Use API without Authorization
var fbapi = require('facebook-api');
var client = fbapi.user(null); // do not set an access token
- client.getUser("btaylor").info(viewback);
+ client.get("btaylor").info(viewback);
> Data: {"id":"220439","name":"Bret Taylor","first_name":"Bret","last_name":"Taylor","link":"http://www.facebook.com/btaylor","gender":"male","locale":"en_US"}
View
19 lib/raw.js
@@ -6,7 +6,20 @@ function raw(method, path, params, callback) {
var facebook_graph_url = 'https://graph.facebook.com';
path = path[0] == '/' ? path: '/' + path;
var url = joinUrl(facebook_graph_url + path, params);
- doRequest(method, url, callback);
+ var parser = JSON.parse;
+ // oauth/access_token's data is not in json
+ if (path == "/oauth/access_token") {
+ parser = querystring.parse;
+ }
+ function cb(er, data) {
+ if(er) {
+ callback(er, null);
+ } else {
+ parsed = parser(data);
+ callback(er, parsed);
+ }
+ }
+ doRequest(method, url, cb);
};
function doRequest(method, url, callback) {
@@ -35,7 +48,7 @@ function doRequest(method, url, callback) {
},
null);
} else {
- callback(null, JSON.parse(result));
+ callback(null, result);
}
});
});
@@ -48,4 +61,4 @@ function joinUrl(path, params) {
if (typeof module == "object" && typeof require == "function") {
module.exports = raw;
-}
+}
View
2 lib/user.js
@@ -112,7 +112,7 @@ function User(raw) {
} else if (data.error) {
callback(data.error, null);
} else {
- callback(null, data.accessToken);
+ callback(null, data.access_token);
}
});
}
View
4 package.json
@@ -1,7 +1,7 @@
{
"name": "facebook-api",
"description": "offering high level and low level calls against the graph API",
- "version": "0.1.0",
+ "version": "0.1.1",
"author": "Mark Engel <mark.c.engel@gmail.com>",
"keywords": [
"facebook"
@@ -21,4 +21,4 @@
""
],
"homepage": "https://github.com/mren/facebook-api"
-}
+}

0 comments on commit 8af7cfe

Please sign in to comment.
Something went wrong with that request. Please try again.