Beispiel #1
0
        public static Task FromJson(Json.JsonObject json)
        {
            var uuid         = Guid.Parse(json.GetNamedString("uuid"));
            var status       = statusLUT[json.GetNamedString("status")];
            var description  = json.GetNamedString("description");
            var entered      = new Timestamp(json.GetNamedString("entry"));
            var lastModified = new Timestamp(json.GetNamedString("modified"));
            var tags         = noTags;

            if (json.ContainsKey("tags"))
            {
                tags = ImmutableList.CreateRange(json.GetNamedArray("tags").Select(value => value.GetString()));
            }
            var additionalAttributes = ImmutableDictionary.CreateRange(json.Where(entry => !handledAttributes.Contains(entry.Key)));

            return(new Task(uuid, status, description, entered, lastModified, tags, additionalAttributes));
        }
        /// <summary>
        /// This function extracts access_token from the response returned from web authentication broker
        /// and uses that token to get user information using facebook graph api.
        /// </summary>
        /// <param name="responseData">responseData returned from AuthenticateAsync result.</param>
        private async Task GetFacebookUserNameAsync(string responseData)
        {
            var decoder = new WwwFormUrlDecoder(responseData);
            var error   = decoder.TryGetValue("error");

            if (error != null)
            {
                FacebookUserName.Text = $"Error: {error}";
                return;
            }

            // You can store access token locally for further use.
            string access_token = decoder[0].Value;

            this.fb_token = decoder[0].Value;
            string expires_in = decoder.TryGetValue("expires_in"); // expires_in is optional

            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
            Uri uri = new Uri($"https://graph.facebook.com/me?fields=id,name,picture,birthday&access_token={Uri.EscapeDataString(access_token)}");

            HttpGetStringResult result = await httpClient.TryGetStringAsync(uri);

            if (result.Succeeded)
            {
                Windows.Data.Json.JsonObject userInfo = Windows.Data.Json.JsonObject.Parse(result.Value).GetObject();
                FacebookUserName.Text = userInfo.GetNamedString("name");
                this.userID           = userInfo.GetNamedString("id");
            }
            else
            {
                FacebookUserName.Text = "Error contacting Facebook";
            }

            Windows.Web.Http.HttpClient httpClient2 = new Windows.Web.Http.HttpClient();
            Uri uri2 = new Uri($"https://graph.facebook.com/{this.userID}/accounts?fields=name,access_token&access_token={this.fb_token}");

            HttpGetStringResult myresult = await httpClient.TryGetStringAsync(uri2);

            if (myresult.Succeeded)
            {
                Windows.Data.Json.JsonObject userInfo2 = Windows.Data.Json.JsonObject.Parse(myresult.Value).GetObject();
                this.Page_token = userInfo2["data"].GetArray()[0].GetObject().GetNamedString("access_token");
            }
            else
            {
                Debug.Write("man ta osso!");
            }

            Windows.Web.Http.HttpClient httpClient3 = new Windows.Web.Http.HttpClient();
            Uri uri3 = new Uri($"https://graph.facebook.com/{this.userID}/accounts?access_token={this.fb_token}");

            HttpGetStringResult result3 = await httpClient.TryGetStringAsync(uri3);

            if (result3.Succeeded)
            {
                Windows.Data.Json.JsonObject userInfo = Windows.Data.Json.JsonObject.Parse(result3.Value).GetObject();
                this.PageId = userInfo["data"].GetArray()[0].GetObject().GetNamedString("id");
            }
            else
            {
                FacebookUserName.Text = "Error contacting Facebook";
            }
        }