root/trunk/nuxleus/Source/Xameleon/Function/Facebook.cs

Revision 4148, 4.0 kB (checked in by xmlhacker, 1 year ago)

updated to use proper extensions projects

Line 
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Web;
5 using System.Text;
6 using Nuxleus.Bucker;
7 using Nuxleus.Authentication;
8 using Nuxleus.Extension.Facebook;
9
10 namespace Xameleon.Function {
11
12   public static class Facebook {
13
14     /// <summary>
15     /// First function to call in order to get the authentication token used to
16     /// sign the user in and open his session.
17     /// </summary>
18     public static string GetAuthenticationToken(HttpContext context) {
19       //Facebook application API key, public, and global to all users
20       // Where should this be pulled from? The context?
21       // Or should this be passed as parameter of the function?
22       string apiKey = "";
23       string secret = ""; //Facebook application secret key global to all users
24      
25       SortedDictionary<string, object> parameters = new SortedDictionary<string, object>();
26       parameters.Add("api_key", apiKey);
27       parameters.Add("method", "auth.createToken");
28       parameters.Add("v", "1.0");
29
30       // This performs the actual all to the service
31       return Nuxleus.Extension.Facebook.Facebook.Call(secret, parameters);
32     }
33
34     /// <summary>
35     /// Called to sign the user in and activate the acknowledge the authentication token.
36     /// This must be called before OpenUserSession.
37     /// </summary>
38     public static void SignInUser(HttpContext context) {
39       // Again where these should come from?
40       // Or rather, how do get we access to them?
41       // Should we call memcached?
42       string authToken = "";
43       string apiKey = ""; //Facebook application API key, public, and global to all users
44       string email = "";
45       string password = "";
46      
47       Nuxleus.Authentication.Facebook.Authenticate(email, password, authToken, apiKey);
48     }
49
50     public static string OpenUserSession(HttpContext context) {
51       string authToken = "";
52       string secret = ""; //Facebook application secret key global to all users
53       string apiKey = ""; //Facebook application API key, public, and global to all users
54      
55       SortedDictionary<string, object> parameters = new SortedDictionary<string, object>();
56       parameters.Add("api_key", apiKey);
57       parameters.Add("auth_token", authToken);
58       parameters.Add("method", "auth.getSession");
59       parameters.Add("v", "1.0");
60
61       return Nuxleus.Extension.Facebook.Facebook.Call(secret, parameters);
62     }
63
64     public static string GetFriends(HttpContext context) {
65       string authToken = "";
66       string secret = ""; //Facebook application secret key global to all users
67       string apiKey = ""; //Facebook application API key, public, and global to all users
68       string sessionKey = ""; //returned by the OpenUserSession call. It is per user.
69
70       SortedDictionary<string, object> parameters = new SortedDictionary<string, object>();
71
72       parameters.Add("api_key", apiKey);
73       parameters.Add("call_id", DateTime.Now.Ticks);
74       parameters.Add("method", "friends.get");
75       parameters.Add("session_key", sessionKey);
76       parameters.Add("v", "1.0");
77
78       return Nuxleus.Extension.Facebook.Facebook.Call(secret, parameters);
79     }
80
81     public static string Notify(HttpContext context) {
82       string authToken = "";
83       string secret = ""; //Facebook application secret key global to all users
84       string apiKey = ""; //Facebook application API key, public, and global to all users
85       string sessionKey = ""; //returned by the OpenUserSession call. It is per user.
86       string[] uids = null; // uuids of destination
87       string message = String.Empty;
88
89       SortedDictionary<string, object> parameters = new SortedDictionary<string, object>();
90
91       parameters.Add("api_key", apiKey);
92       parameters.Add("call_id", DateTime.Now.Ticks);
93       parameters.Add("method", "notifications.send");
94       parameters.Add("notification", message);
95       parameters.Add("session_key", sessionKey);
96       parameters.Add("to_ids", uids);
97       parameters.Add("v", "1.0");
98
99       return Nuxleus.Extension.Facebook.Facebook.Call(secret, parameters);
100     }
101   }
102 }
Note: See TracBrowser for help on using the browser.