Exemple #1
0
        public static FacebookPost GetFacebookPost(string postId      = "146505212039213_2464275336928844",
                                                   string accesstoken =
                                                   "EAACEdEose0cBACdtZB9WceN0NZAXJy6ZAERvZAIFWYEL2cZCFPdZBAS7OaZAEF2lx6lp4cNZB987c9rNhrSyZAdFZAj7eTamfSPROPZBy0XWnhJaZBoUKZBVUwgFAkd3wOIK7myy3hjEyGg0ZBuobdnobsiGfpJZBxm5ztRwqSXonyFtoxxTQZDZD")
        {
            try
            {
                var facebookpost          = new FacebookPost();
                var facebookCommentserror = new FacebookError();

                var graphapi    = new GraphApi(accesstoken);
                var graphapiurl = graphapi.PostsUrl(postId);

                var res      = new GraphApiResponse();
                var response = res.GetResponse(graphapiurl);

                var serializer = new JavaScriptSerializer();
                facebookpost = serializer.Deserialize <FacebookPost>(response);

                if (facebookpost == null)
                {
                    facebookCommentserror = serializer.Deserialize <FacebookError>(response);

                    if (facebookCommentserror.error != null)
                    {
                        // Login status or access token has expired, been revoked, or is otherwise invalid. Handle expired access tokens.
                        // Access token has expired
                        if (facebookCommentserror.error.code == "190" &&
                            facebookCommentserror.error.error_subcode == "463")
                        {
                            //Get new Access Token
                        }
                    }
                }
                return(facebookpost);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        public Model.FacebookPost GetFacebookPost(string postId, string accesstoken)
        {
            try
            {
                var facebookpost          = new Model.FacebookPost();
                var facebookCommentserror = new FacebookError();

                var graphapi    = new GraphApi(accesstoken);
                var graphapiurl = graphapi.PostsUrl(postId);

                var res      = new GraphApiResponse();
                var response = res.GetResponse(graphapiurl);

                var serializer = new JavaScriptSerializer();
                facebookpost = serializer.Deserialize <Model.FacebookPost>(response);

                if (facebookpost == null)
                {
                    facebookCommentserror = serializer.Deserialize <FacebookError>(response);

                    if (facebookCommentserror.error != null)
                    {
                        // Login status or access token has expired, been revoked, or is otherwise invalid. Handle expired access tokens.
                        // Access token has expired
                        if (facebookCommentserror.error.code == "190" &&
                            facebookCommentserror.error.error_subcode == "463")
                        {
                            //Get new Access Token
                        }
                    }
                }
                return(facebookpost);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }