Reputation: 1270
I am developing a service that requires the user to provide it with a Facebook's app id, right now the user can type in anything and it will accept it, i am trying to enforce some rules
by calling the graph and checking if that app exists in the first place.
but i don't know how to get that done right now.
Upvotes: 2
Views: 320
Reputation: 1270
First of all the context in which I am going to answer is through an asp.net MVC 5 project.
In order to keep things clean we are going to build a little helper class called AppData .
using System.Web.Helpers; using System.Net; public class AppData { public string id { get; set; } public string name { get; set; } public string description { get; set; } public string category { get; set; } public string link { get; set; } public string icon_url { get; set; } public string logo_url { get; set; } public string company { get; set; } public int daily_active_users { get; set; } public int monthly_active_users { get; set; } public int daily_active_users_rank { get; set; } public int monthly_active_users_rank { get; set; } public static AppData GetAppData(string id) { try { string url = "http://graph.facebook.com/" + id; var json = new WebClient().DownloadString(url); return Json.Decode<AppData>(json); } catch { return null; } } }
this class will have the responsibility of calling the Facebook graph using the Facebook app id and then deserializing ( decoding ) the json response if any to a new instance of the AppData Class and returning it back to the user,, if there is no such app we will return null to the user,, the user can then check against null value to know if that app id is real or not and get useful info for their request over the network.
Upvotes: 1