public static void save(Facebook facebook)
 {
     clear();
     settings.Add(ACCESS_TOKEN, facebook.getAccessToken());
 }
Beispiel #2
0
        /// <summary>
        /// Request to Facebook API
        /// </summary>
        /// <param name="path">Request path</param>
        /// <param name="mapParams">Request parameters</param>
        /// <param name="method">Request method</param>
        /// <param name="callback">Method to be called when request finishes</param>
        public static void request(String path, Dictionary <String, String> mapParams, String method, Action <String, NetmeraException> callback)
        {
            if (facebook != null && facebook.isSessionValid())
            {
                try
                {
                    FacebookClient fb = new FacebookClient(facebook.getAccessToken());

                    var parameters = new Dictionary <String, Object>();
                    if (mapParams != null && mapParams.Count != 0)
                    {
                        foreach (var key in mapParams.Keys)
                        {
                            parameters.Add(key, mapParams[key]);
                        }
                    }

                    if (!String.IsNullOrEmpty(method) && method.ToUpper().Trim() == "POST")
                    {
                        fb.PostCompleted += (o, e) =>
                        {
                            if (e.Error != null)
                            {
                                if (callback != null)
                                {
                                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_FB_ERROR, e.Error.Message));
                                }
                            }
                            else
                            {
                                var result = (IDictionary <String, Object>)e.GetResultData();
                                callback(result.ToString(), null);
                            }
                        };
                        fb.PostAsync(path, parameters);
                    }
                    else
                    {
                        fb.GetCompleted += (o, e) =>
                        {
                            if (e.Error != null)
                            {
                                if (callback != null)
                                {
                                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_FB_ERROR, e.Error.Message));
                                }
                            }
                            else
                            {
                                var result = (IDictionary <String, Object>)e.GetResultData();
                                callback(result.ToString(), null);
                            }
                        };
                        fb.GetAsync(path, parameters);
                    }
                }
                catch
                {
                    if (callback != null)
                    {
                        callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_FB_ERROR, "Request error occured."));
                    }
                }
            }
            else
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_FB_ERROR, "Must first login."));
                }
            }
        }