/* appjet:version 0.1 */ /* appjet:library */ // Copyright (c) 2010, Herbert Vojčík // Licensed by MIT license (http://www.opensource.org/licenses/mit-license.php) import("facebook", "storage"); var _u = import({}, "lib-support/useful"); fb.OAuthInterface = function () {}; fb.OAuthInterface.prototype.restApi = function (method, args) { return wpost("https://api.facebook.com/method/"+method, this.withToken(args)); }; fb.OAuthInterface.prototype.graphApiGet = function (path, args) { return wget("https://graph.facebook.com/"+path, this.withToken(args)); }; fb.OAuthInterface.prototype.graphApiPost = function (path, args) { return wpost("https://graph.facebook.com/"+path, this.withToken(args)); }; fb.OAuthInterface.prototype.withToken = function (args) { var token = this._token || (this._token = this.obtainToken()); return token ? _u.extend({access_token:token}, args) : args; }; fb.free = new fb.OAuthInterface; fb.free.obtainToken = function () {}; fb.offline = new fb.OAuthInterface; fb.offline.obtainToken = function () { var obtained = fb.free.graphApiPost("oauth/access_token", { grant_type: "client_credentials", client_id: storage.facebooklib.appId, client_secret: storage.facebooklib.secret }).split('='); if (obtained[0] === "access_token") { return obtained[1]; } }; fb.online = new fb.OAuthInterface; fb.online.obtainToken = function () { var obtained = eval("("+fb.free.graphApiPost("oauth/exchange_sessions", { sessions: fb.sessionKey, client_id: storage.facebooklib.appId, client_secret: storage.facebooklib.secret })+")"); // XXX JSON.parse return obtained[0].access_token; };