Example #1
0
        public async Task <IOAuth2Graph> GetGraphAsync(IAuthorizationState authState, string[] fields = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if ((authState != null) && (authState.AccessToken != null))
            {
                var    httpClient = new HttpClient(this.CreateAuthorizingHandler(authState));
                string fieldsStr  = (fields == null) || (fields.Length == 0) ? FacebookGraph.Fields.Defaults : string.Join(",", fields);

                using (
                    var response = await httpClient.GetAsync("https://graph.Facebook.com/me?fields=" + fieldsStr, cancellationToken)) {
                    response.EnsureSuccessStatusCode();
                    using (var responseStream = await response.Content.ReadAsStreamAsync()) {
                        return(FacebookGraph.Deserialize(responseStream));
                    }
                }
            }

            return(null);
        }
        public IOAuth2Graph GetGraph(IAuthorizationState authState, string[] fields = null)
        {
            if ((authState != null) && (authState.AccessToken != null))
            {
                string fieldsStr = (fields == null) || (fields.Length == 0) ? FacebookGraph.Fields.Defaults : string.Join(",", fields);
                fieldsStr = string.Join(",", fieldsStr.Split(',').Distinct().ToList());
                var request = System.Net.WebRequest.Create("https://graph.Facebook.com/me?access_token=" + Uri.EscapeDataString(authState.AccessToken) + "&fields=" + fieldsStr);

                using (var response = request.GetResponse())
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        return(FacebookGraph.Deserialize(responseStream));
                    }
                }
            }

            return(null);
        }
        public IOAuth2Graph GetGraph(IAuthorizationState authState, string[] fields = null)
        {
            if ((authState != null) && (authState.AccessToken != null))
            {
                string fieldsStr = (fields == null) || (fields.Length == 0) ? FacebookGraph.Fields.Defaults : string.Join(",", fields);

                WebRequest  request  = WebRequest.Create("https://graph.Facebook.com/me?access_token=" + Uri.EscapeDataString(authState.AccessToken) + "&fields=" + fieldsStr);
                WebResponse response = request.GetResponse();

                if (response != null)
                {
                    Stream responseStream = response.GetResponseStream();

                    if (responseStream != null)
                    {
                        return(FacebookGraph.Deserialize(responseStream));
                    }
                }
            }

            return(null);
        }