Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string callbackPath = Request.Url.AbsoluteUri.Replace(Request.Url.Segments[Request.Url.Segments.Length - 1], "") + "Callback.aspx";

        if (!string.IsNullOrEmpty(Request.Url.Query)) callbackPath = callbackPath.Replace(Request.Url.Query, "");

        if (!string.IsNullOrEmpty(Request.QueryString["wall_post"]))
        {
            if (Request.QueryString["wall_post"].Contains("/$articles$/"))
            {
                Session["fbWallPost"] = Request.QueryString["wall_post"].Replace("/$articles$/", "/articles/");
                Session["PostArticleForCms"] = true;
            }
            else
            {
                Session["fbWallPost"] = Request.QueryString["wall_post"];
            }
            if (Request.QueryString["picture_url"] != null && !string.IsNullOrEmpty(Request.QueryString["picture_url"].ToString()))
            {
                Session["fbPictureUrl"] = Request.QueryString["picture_url"];
            }
            if (Request.QueryString["title"]!= null && !string.IsNullOrEmpty(Request.QueryString["title"].ToString()))
            {
                Session["fbTitle"] = Request.QueryString["title"];
            }
            if (Request.QueryString["desc"] != null && !string.IsNullOrEmpty(Request.QueryString["desc"].ToString()))
            {
                Session["fbDesc"] = Request.QueryString["desc"].Replace("<br/>", "\n");
            }
            if (Request.QueryString["valArticleUrl"] != null && !string.IsNullOrEmpty(Request.QueryString["valArticleUrl"].ToString()))
            {
                Session["CmsArticleUrl"] = Request.QueryString["valArticleUrl"].Replace("/$articles$/", "/articles/");
            }

            //  Response.Redirect(String.Format("http://twitter.com/oauth/authorize?oauth_token={0}", tk.Token), true);
        }
        Session["fbCallback"] = callbackPath;
        oAuthFacebook oFB = new oAuthFacebook(callbackPath);
        Response.Redirect(oFB.AuthorizationLinkGet());
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        oAuthFacebook oAuth = new oAuthFacebook(Session["fbCallback"].ToString());
        string PostArticleForCms = string.Empty;
        string json = string.Empty;
        string pictrue = string.Empty;
        string title = string.Empty;
        string desc = string.Empty;
        if (Request["code"] == null)
        {
            //Redirect the user back to Facebook for authorization.
            Response.Redirect(oAuth.AuthorizationLinkGet());
        }
        else
        {
            try
            {
                //Get the access token and secret.
                oAuth.AccessTokenGet(Request["code"]);

                if (oAuth.Token.Length > 0)
                {
                    string tmpWallPost = Session["fbWallPost"].ToString();
                    if (Session["fbPictureUrl"] != null && !string.IsNullOrEmpty((Session["fbPictureUrl"].ToString())))
                    {
                        pictrue = Session["fbPictureUrl"].ToString();
                    }
                    if (Session["fbTitle"] != null && !string.IsNullOrEmpty((Session["fbTitle"].ToString())))
                    {
                        title = Session["fbTitle"].ToString();
                    }
                    if (Session["fbDesc"] != null && !string.IsNullOrEmpty((Session["fbDesc"].ToString())))
                    {
                        desc = Session["fbDesc"].ToString();
                    }
                    if (Session["PostArticleForCms"] != null && !string.IsNullOrEmpty(Session["PostArticleForCms"].ToString()))
                    {
                        string ArticleLink = Session["CmsArticleUrl"].ToString();

                        // send image tag with query string only if image exists
                        if (!string.IsNullOrEmpty(pictrue))
                        {
                            //We now have the credentials, so we can start making API calls
                            json = oAuth.WebRequest(oAuthFacebook.Method.POST, "https://graph.facebook.com/me/feed",
                               "access_token=" + oAuth.Token + "&message=" + tmpWallPost + "&picture=" + pictrue + "&link=" + ArticleLink + "&name=" + title + "&caption=Powered By DevInfo&description=" + desc);
                        }
                        else
                        {//We now have the credentials, so we can start making API calls
                            json = oAuth.WebRequest(oAuthFacebook.Method.POST, "https://graph.facebook.com/me/feed",
                               "access_token=" + oAuth.Token + "&message=" + tmpWallPost + "&link=" + ArticleLink + "&name=" + title + "&caption=Powered By DevInfo&description=" + desc);
                        }

                    }
                    else
                    {
                        if (string.IsNullOrEmpty(desc) && string.IsNullOrEmpty(title))
                        {
                             json = oAuth.WebRequest(oAuthFacebook.Method.POST, "https://graph.facebook.com/me/feed",
                                "access_token=" + oAuth.Token + "&message=" + tmpWallPost);
                            Response.Write("<script language='javascript'> { self.close() }</script>");
                            Session["fbWallPost"] = "";
                        }
                        else
                        {

                        //We now have the credentials, so we can start making API calls
                        json = oAuth.WebRequest(oAuthFacebook.Method.POST, "https://graph.facebook.com/me/feed",
                           "access_token=" + oAuth.Token + "&message=" + tmpWallPost + "&picture=" + pictrue + "&name=Visuaization" + "&caption=" + title + "&description=" + desc);
                        //picture=http://fbrell.com/f8.jpg&
                        //name=Facebook%20Dialogs&
                        //caption=Reference%20Documentation&
                        //description=Using%20Dialogs%20to%20interact%20with%20users.&
                        }
                    }
                    Response.Write("<script language='javascript'> { self.close() }</script>");
                    Session.Remove("fbWallPost");
                    Session.Remove("fbPictureUrl");
                    Session.Remove("fbTitle");
                    Session.Remove("fbDesc");
                    Session.Remove("PostArticleForCms");
                    Session.Remove("CmsArticleUrl");
                }
            }
            catch (Exception Ex)
            {
                Global.WriteErrorsInLogFolder(Ex.Message + "-------------------------" + Ex.InnerException + "-------------------------" + Ex.StackTrace);
                Response.Write("<script language='javascript'> { self.close() }</script>");
                Session.Remove("fbWallPost");
                Session.Remove("fbPictureUrl");
                Session.Remove("fbTitle");
                Session.Remove("fbDesc");
                Session.Remove("PostArticleForCms");
                Session.Remove("CmsArticleUrl");
            }
        }
    }
Ejemplo n.º 3
0
 public FacebookAPI(oAuthFacebook _oAuth)
 {
     oAuth = _oAuth;
 }