xamarin / Xamarin.Social

Xamarin.Social
Apache License 2.0
124 stars 74 forks source link

Facebook should make accessing Graph urls easy #2

Open praeclarum opened 11 years ago

praeclarum commented 11 years ago

Add a GetGraphNode or similar function to FacebookService.

Right now we have to type:

var req = s.CreateRequest (
    "GET",
    new Uri ("https://graph.facebook.com/598072388?fields=friends.fields(first_name,name,gender,updated_time)"),
    account);
var resp = await req.GetResponseAsync ();
var json = JsonObject.Parse (resp.GetResponseText ());

It would be nice to get that down to 1 line:

    public static async Task<JsonObject> GetGraphLinkAsync (this FacebookService facebook, string link, Account account)
    {
        var req = facebook.CreateRequest (
            "GET",
            new Uri (link),
            account);
        using (var resp = await req.GetResponseAsync ()) {
            return (JsonObject)JsonObject.Parse (resp.GetResponseText ());
        }
    }

    public static async Task<JsonObject> GetGraphAsync (this FacebookService facebook, string query, Account account)
    {
        var req = facebook.CreateRequest (
            "GET",
            new Uri ("https://graph.facebook.com/" + query),
            account);
        using (var resp = await req.GetResponseAsync ()) {
            return (JsonObject)JsonObject.Parse (resp.GetResponseText ());
        }
    }