private static void LoginNavigationStarted(Uri url, object state) { FacebookOAuthResult result; // Check if we're waiting for user input or if login is complete if (_client.TryParseOAuthCallbackUrl(url, out result)) { // Login complete if (result.IsSuccess) { AccessToken = result.AccessToken; Expires = result.Expires; _client.AccessToken = AccessToken; Settings.Set(TOKEN_KEY, EncryptionProvider.Encrypt(AccessToken, AppId)); Settings.Set(EXPIRY_DATE_BIN, Expires.ToBinary()); } _web.Finish(); if (_onHideUnity != null) { _onHideUnity(false); } API("/me?fields=id,name", HttpMethod.GET, fbResult => { if (IsLoggedIn) { UserId = fbResult.Json["id"] as string; UserName = fbResult.Json["name"] as string; Settings.Set(FBID_KEY, UserId); Settings.Set(FBNAME_KEY, UserName); } if (state is FacebookDelegate) { JsonObject jResult = new JsonObject(); jResult.Add(new KeyValuePair<string, object>("authToken", AccessToken)); jResult.Add(new KeyValuePair<string, object>("authTokenExpiry", Expires.ToString())); ((FacebookDelegate)state)(new FBResult() { Json = jResult, Text = jResult.ToString() }); } }); } }
/// <summary> /// Returns a <see cref="FacebookBatchParameter"/> representing FQL multi-query. /// </summary> /// <param name="fql"> /// The fql queries. /// </param> /// <returns> /// The <see cref="FacebookBatchParameter"/>. /// </returns> public FacebookBatchParameter Query(params string[] fql) { Contract.Requires(fql != null); var queryDict = new JsonObject(); for (int i = 0; i < fql.Length; i++) { queryDict.Add(string.Concat("query", i), fql[i]); } HttpMethod = HttpMethod.Get; Path = "/method/fql.multiquery"; Parameters = new JsonObject { { "queries", queryDict } }; return this; }
/// <summary> /// Parses the session value from a cookie. /// </summary> /// <param name="appSecret"> /// The app Secret. /// </param> /// <param name="cookieValue"> /// The session value. /// </param> /// <returns> /// The Facebook session object. /// </returns> internal static FacebookSession ParseCookieValue(string appSecret, string cookieValue) { Contract.Requires(!String.IsNullOrEmpty(appSecret)); Contract.Requires(!String.IsNullOrEmpty(cookieValue)); Contract.Requires(!cookieValue.Contains(","), "Session value must not contain a comma."); // var cookieValue = "\"access_token=124973200873702%7C2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026%7Cvz4H9xjlRZPfg2quCv0XOM5g9_o&expires=1295118000&secret=lddpssZCuPoEtjcDFcWtoA__&session_key=2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026&sig=1d95fa4b3dfa5b26c01c8ac8676d80b8&uid=100001327642026\""; // var result = FacebookSession.Parse("3b4a872617be2ae1932baa1d4d240272", cookieValue); // Parse the cookie var dictionary = new JsonObject(); var parts = cookieValue.Replace("\"", string.Empty).Split('&'); foreach (var part in parts) { if (!string.IsNullOrEmpty(part) && part.Contains("=")) { var nameValue = part.Split('='); if (nameValue.Length == 2) { var s = FacebookUtils.UrlDecode(nameValue[1]); dictionary.Add(nameValue[0], s); } } } var signature = GenerateSessionSignature(appSecret, dictionary); if (dictionary.ContainsKey("sig") && dictionary["sig"].ToString() == signature) { return new FacebookSession(dictionary); } return null; }
private object BuildExchangeCodeForAccessTokenResult(string json) { var returnParameter = new JsonObject(); FacebookUtils.ParseQueryParametersToDictionary("?" + json, returnParameter); // access_token=string&expires=long or access_token=string // Convert to JsonObject to support dynamic and be consistent with the rest of the library. var jsonObject = new JsonObject(); jsonObject["access_token"] = returnParameter["access_token"]; // check if expires exist coz for offline_access it is not present. if (returnParameter.ContainsKey("expires")) { jsonObject.Add("expires", Convert.ToInt64(returnParameter["expires"])); } return jsonObject; }
public void RateBook(Guid userId, string bookUrl, short ratingValue, string reviewUrl = null, string actionId = null) { var socialUserId = GetSocialUserId(userId); if (string.IsNullOrEmpty(socialUserId)) return; if (!string.IsNullOrEmpty(actionId)) DeleteAction(actionId); Task.Factory.StartNew(() => { var postParams = new JsonObject { {"book", GetNormalizedUrl(bookUrl)}, {"rating:value", ratingValue}, {"rating:scale", 5} }; if (!string.IsNullOrEmpty(reviewUrl) ) postParams.Add("review", GetNormalizedUrl(reviewUrl)); var client = new FacebookClient(AccessToken); client.Post(string.Format("{0}/books.rates", socialUserId), postParams); SetBookStat(userId, bookUrl, UserStatStateEnum.Read); }); }
/// <summary> /// Returns a <see cref="FacebookBatchParameter"/> representing FQL multi-query. /// </summary> /// <param name="fql"> /// The fql queries. /// </param> /// <returns> /// The <see cref="FacebookBatchParameter"/>. /// </returns> public FacebookBatchParameter Query(params string[] fql) { if (fql == null) throw new ArgumentNullException("fql"); if (fql.Length == 0) throw new ArgumentException("At least one fql query required.", "fql"); var queryDict = new JsonObject(); for (int i = 0; i < fql.Length; i++) queryDict.Add(string.Concat("query", i), fql[i]); HttpMethod = HttpMethod.Get; Path = "fql"; Parameters = new JsonObject { { "q", queryDict } }; return this; }