12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- /* 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");
- fb.OAuthInterface = function () {
- }
- fb.OAuthInterface.prototype.restApi = function (method, args) {
- return wget("https://api.facebook.com/"+method+this.tokenString(), args);
- };
- fb.OAuthInterface.prototype.graphApiGet = function (path, args) {
- return wget("https://graph.facebook.com/"+path+this.tokenString(), args);
- };
- fb.OAuthInterface.prototype.graphApiPost = function (path, args) {
- return wpost("https://graph.facebook.com/"+path+this.tokenString(), args);
- };
- fb.OAuthInterface.prototype.tokenString = function () {
- var token = this._token || (this._token = this.obtainToken());
- return token ? "?access_token="+token : "";
- };
- 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;
- };
|