Ejemplo n.º 1
0
        public string GetShortToken(string pageId)
        {
            var newToken = string.Empty;
            var url      = String.Format("{0}/{1}/accounts?access_token={2}", ConfigurationHandler.FacebookGraphAPI,
                                         ConfigurationHandler.FacebookPersonalId, ConfigurationHandler.FacebookPageToken);
            var content = WebHandler.DownloadContent(url);
            var jsonObj = (JObject)JsonConvert.DeserializeObject(content);

            if (jsonObj != null && jsonObj["data"] != null && jsonObj["data"].Children().Any())
            {
                foreach (var subresult in jsonObj["data"].Children())
                {
                    if (pageId.Equals((subresult.Value <string>("id"))))
                    {
                        var newCredential = new FacebookCredentialViewModel()
                        {
                            Category    = subresult.Value <string>("category"),
                            Name        = subresult.Value <string>("name"),
                            AccessToken = subresult.Value <string>("access_token"),
                            PageId      = Convert.ToInt64(subresult.Value <string>("id"))
                        };

                        newToken = newCredential.AccessToken;
                    }
                }
            }

            return(newToken);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateFacebookCredential(FacebookCredentialViewModel model)
        {
            if (ModelState.IsValid)
            {
                await appUserService.TryUpdateFacebookPassword(UserId, model.Id.GetValueOrDefault(0), model.Username, model.Password);

                UserFacebookCredentials = await appUserService.FacebookCredentials(UserId);

                return(PartialView("~/Views/Account/_FacebookCredentialsListPartial.cshtml", UserFacebookCredentials));
            }
            return(NoContent());
        }