protected List <FacebookPermissionRequest> CheckPermissions( Dictionary <string, FacebookPermissionRequest> RequiredPermissions) { var access_token = HttpContext.Items["access_token"].ToString(); if (!string.IsNullOrEmpty(access_token)) { var appsecret_proof = access_token.GenerateAppSecretProof(); var fb = new FacebookClient(access_token); IEnumerable <FacebookPermissionRequest> MissingPermissions = new List <FacebookPermissionRequest>(); //initialize to an empty list if (RequiredPermissions != null && RequiredPermissions.Count > 0) { //create an array of Facebook Batch Parameters based on list of RequiredPermission FacebookBatchParameter[] fbBatchParameters = new FacebookBatchParameter[RequiredPermissions.Values.Count()]; int idx = 0; foreach (FacebookPermissionRequest required_permssion in RequiredPermissions.Values) { fbBatchParameters[idx] = new FacebookBatchParameter { HttpMethod = HttpMethod.Get, Path = string.Format("{0}{1}", "me/permissions/", required_permssion.permision_scope_value) .GraphAPICall(appsecret_proof) }; required_permssion.granted = false; //initalize all granted indicators to false for each required permission idx++; } dynamic permission_Batchresult = fb.Batch( fbBatchParameters ); if (permission_Batchresult != null) { List <PermissionResults> result = JsonConvert. DeserializeObject <List <PermissionResults> > (permission_Batchresult.ToString()); foreach (FacebookPermissionModel permissionResult in result.SelectMany(x => x.data).Where(y => y.status == "granted")) { RequiredPermissions[permissionResult.permission].granted = true; } MissingPermissions = RequiredPermissions.Values. Where(p => p.granted == false); } } return(MissingPermissions.ToList()); } else { throw new HttpException(404, "Missing Access Token"); } }
/// <summary> /// Upload Multiple Photos /// </summary> /// <param name="parameters"></param> /// <returns></returns> public JsonArray UploadMultiplePhotos(List <Dictionary <string, object> > parameters) { try { FacebookBatchParameter[] batchArray = new FacebookBatchParameter[parameters.Count]; for (int i = 0; i < parameters.Count; i++) { batchArray[i] = new FacebookBatchParameter(HttpMethod.Post, base.pageID + "/photos", parameters[i]); } dynamic result = fb.Batch(batchArray); return(result); } catch (Exception ex) { throw ex; } }
private void BatchRequestExample() { try { var fb = new FacebookClient(_accessToken); dynamic result = fb.Batch( new FacebookBatchParameter { HttpMethod = HttpMethod.Get, Path = "/4" }, new FacebookBatchParameter(HttpMethod.Get, "/me/friend", new Dictionary <string, object> { { "limit", 10 } }), // this should throw error new FacebookBatchParameter("/me/friends", new { limit = 1 }) { Data = new { name = "one-friend", omit_response_on_success = false } }, // use Data to add additional parameters that doesn't exist new FacebookBatchParameter { Parameters = new { ids = "{result=one-friend:$.data.0.id}" } }, new FacebookBatchParameter("{result=one-friend:$.data.0.id}/feed", new { limit = 5 }), new FacebookBatchParameter().Query("SELECT name FROM user WHERE uid="), // fql new FacebookBatchParameter().Query("SELECT first_name FROM user WHERE uid=me()", "SELECT last_name FROM user WHERE uid=me()") // fql multi-query //,new FacebookBatchParameter(HttpMethod.Post, "/me/feed", new { message = "test status update" }) ); // always remember to check individual errors for the batch requests. if (result[0] is Exception) { MessageBox.Show(((Exception)result[0]).Message); } dynamic first = result[0]; string name = first.name; // note: incase the omit_response_on_success = true, result[x] == null // for this example, just comment it out. //if (result[1] is Exception) // MessageBox.Show(((Exception)result[1]).Message); //if (result[2] is Exception) // MessageBox.Show(((Exception)result[1]).Message); //if (result[3] is Exception) // MessageBox.Show(((Exception)result[1]).Message); //if (result[4] is Exception) // MessageBox.Show(((Exception)result[1]).Message); //if (result[5] is Exception) // MessageBox.Show(((Exception)result[1]).Message); //if (result[6] is Exception) // MessageBox.Show(((Exception)result[1]).Message); //if (result[7] is Exception) // MessageBox.Show(((Exception)result[1]).Message); } catch (FacebookApiException ex) { MessageBox.Show(ex.Message); } }
public static void BatchRequest(string accessToken) { try { var fb = new FacebookClient(accessToken); var result = (IList <object>)fb.Batch( new FacebookBatchParameter("me"), new FacebookBatchParameter(HttpMethod.Get, "me/friends", new { limit = 10 })); var result0 = result[0]; var result1 = result[1]; // Note: Always check first if each result set is an exeption. if (result0 is Exception) { var ex = (Exception)result0; // Note: make sure to handle this exception. throw ex; } else { var me = (IDictionary <string, object>)result0; var name = (string)me["name"]; Console.WriteLine("Hi {0}", name); } Console.WriteLine(); if (result1 is Exception) { var ex = (Exception)result1; // Note: make sure to handle this exception. throw ex; } else { var friends = (IList <object>)((IDictionary <string, object>)result1)["data"]; Console.WriteLine("Some of your friends: "); foreach (IDictionary <string, object> friend in friends) { Console.WriteLine(friend["name"]); } } } catch (FacebookApiException ex) { // Note: make sure to handle this exception. throw; } }
public static void BatchRequestWithFqlMultiQuery(string accessToken) { try { var fb = new FacebookClient(accessToken); var result = (IList <object>)fb.Batch( new FacebookBatchParameter("/4"), new FacebookBatchParameter().Query( "SELECT first_name FROM user WHERE uid=me()", "SELECT last_name FROM user WHERE uid=me()")); var result0 = result[0]; var result1 = result[1]; // Note: Always check first if each result set is an exeption. if (result0 is Exception) { var ex = (Exception)result0; // Note: make sure to handle this exception. throw ex; } else { Console.WriteLine("Batch Result 0: {0}", result0); } Console.WriteLine(); if (result1 is Exception) { var ex = (Exception)result1; // Note: make sure to handle this exception. throw ex; } else { var fqlResult = (IList <object>)(((IDictionary <string, object>)result1)["data"]); var fqlResultSet0 = ((IDictionary <string, object>)fqlResult[0])["fql_result_set"]; Console.Write(fqlResultSet0); Console.WriteLine(); var fqlResultSet1 = ((IDictionary <string, object>)fqlResult[1])["fql_result_set"]; Console.WriteLine(fqlResultSet1); } } catch (FacebookApiException ex) { // Note: make sure to handle this exception. throw; } }
/// <summary> /// Método que devuelve en una lista de diccionarios todas las noticias con imagenes y mensajes adheridos /// </summary> /// <param name="limit"> El límite de noticias que se desea. Por defecto, 100 </param> /// <returns>Lista de diccionarios. El diccionario tiene: From, Message, Caption, ImageUrl, Date...</returns> public static List <Dictionary <string, object> > GetNewsWithImages(int limit = 100) { try { dynamic info = client.Batch(new FacebookBatchParameter(HttpMethod.Get, "poloitchaco/feed?limit=" + limit.ToString()), new FacebookBatchParameter(HttpMethod.Get, "informatorio/feed?limit=" + limit.ToString())); List <Dictionary <string, object> > Result = new List <Dictionary <string, object> >(); foreach (var item in info) { foreach (var post in item.data) { Dictionary <string, object> New = new Dictionary <string, object>(); string temp = Convert.ToString(post); if (post.type == "photo" & (post.status_type == "added_photos" | post.status_type == "shared_story") & temp.Contains("message") & !temp.Contains("Informatorio shared POLO IT CHACO's photo")) { New.Add("ID", post.id); New.Add("From", post.from.name); New.Add("Message", post.message); New.Add("Caption", post.caption); string ImageURL = GetImageUrl(post.object_id); New.Add("ImageUrl", GetImageUrl(post.object_id)); New.Add("Link", post.link); New.Add("Date", post.created_time); Result.Add(New); } } } Result.OrderByDescending(x => x["Date"]); return(Result); } catch (Facebook.WebExceptionWrapper fe) { throw fe; } }
private void BatchRequestNullReferenceExceptionWhenOmitReponseOnSuccessIsTrue(string accessToken) { Test("(#5883) Batch Request NullReferenceException when omit_response_on_success = true", () => { var fb = new FacebookClient(accessToken); return(fb.Batch( new FacebookBatchParameter("/me") { Data = new { omit_respone_on_success = true, name = "get-uid" } }, new FacebookBatchParameter("/", new { ids = "result=get-uid:$..id" }))); }); }
private void BatchRequestNullReferenceExceptionWhenOmitReponseOnSuccessIsTrue(string accessToken) { Test("(#5883) Batch Request NullReferenceException when omit_response_on_success = true", () => { var fb = new FacebookClient(accessToken); return fb.Batch( new FacebookBatchParameter("/me") { Data = new { omit_respone_on_success = true, name = "get-uid" } }, new FacebookBatchParameter("/", new { ids = "result=get-uid:$..id" })); }); }