【问题标题】:C# Facebook SDK: How toC# Facebook SDK:如何
【发布时间】:2012-07-06 02:17:52
【问题描述】:

我已尝试找到以下问题的答案至少一小时,但没有成功。 我有 WPF 项目 (C#),我有 webBrowser 控件来导航到我的 Facebook 页面http://www.facebook.com/TennisHelper,我想做接下来的几件事:

  1. 我想通过在我的应用程序中创建包含电子邮件和密码的用户设置来避免登录,但我不知道如何使用 C# Facebook SDK 做到这一点,

  2. 我希望我的用户能够通过 textBox 控件在该页面上发布文本帖子,

  3. 我想让我的用户能够将照片从他的计算机直接发布到该页面,但不创建新相册。只是为了在页面墙上发布图片。

我在谷歌上搜索所有这些问题,但没有成功

【问题讨论】:

    标签: c# wpf facebook sdk desktop


    【解决方案1】:

    让我知道您的实际要求。我认为您的第一个要求是在您的网站登录页面中添加一个 facebook 登录(或注册 facebook 页面)按钮。

    第1步:您需要在facebook上注册一个新的facebook应用程序。 第 2 步:安装 facebook c# sdk。您可以手动下载 zip 文件或使用 nuget 安装它。我推荐第二个选项。我使用的是 c# sdk 5.4.1 What is nuget? How to install a package using nuget? 第 3 步:现在您可以将名称空间 facebook 添加到页面 第4步:在登录页面(比如login.aspx)中插入一个登录按钮(只是一个带有文本登录的按钮)。让它成为button1 第5步:点击按钮重定向到另一个页面(让login1.aspx) 这是登录1的示例代码

    使用 Facebook;//

      FacebookOAuthClient fb = new FacebookOAuthClient();
        UriBuilder red = new UriBuilder("www.example.com/Login1.aspx");
        protected void Page_Load(object sender, EventArgs e)
        {
    
            string appid = "{your app id}";
            string appsecret = "{your app secret}";
            string permissions = "publish_stream";
    
           if(Request.QueryString["code"] == null)
            {
    
                try
                {
    
                Response.Redirect("https://www.facebook.com/dialog/oauth?client_id=" + appid + "&redirect_uri=" + red.Uri.ToString() + "&scope=" + permissions +"&state=djfjfdjj");
                }
                catch (Exception b)
                {
    
                    Label1.Text = b.ToString();
                }
                }
            else
            {
                try
                {
    
                    FacebookOAuthClient cl = new FacebookOAuthClient();
    
    
    
                    cl.RedirectUri = red.Uri;
                    cl.AppId = appid;
                    cl.AppSecret = appsecret;
    
    
                 dynamic result = cl.ExchangeCodeForAccessToken(Request.QueryString["code"]);
                     Label1.Text = Convert.ToString(result);
                  if (result["access_token"] != null)
                     {
                         Session["access_token"] = result["access_token"].ToString();//Now you have access token
    
                         Response.Redirect("Welcome.aspx");//replace welcome.aspx
    
    
                     }
                     else
                     {
                         Label1.Text = "Unable to authenticate\n Please try again later";
                     }
                }
                catch(Exception b)
                {
                    Label1.Text = b.ToString();
    
                }
            }
    
        }
    

    现在您已经在会话中保存了访问令牌。

    用于获取客户的基本信息

    dynamic me=fb.Get("\me");
    

    它包括当前用户的名字,姓氏,电子邮件地址,位置,图像网址等。现在您可以使用此电子邮件或名称来验证您的用户或注册新用户等。(最多你)。

    可以在该页面上发布,但很困难How can I use the Facebook C# SDK to post on Facebook Pages

    【讨论】:

    • 为什么是appid?我的应用程序不是 facebook 应用程序,它是基于 WPF 的桌面应用程序
    【解决方案2】:

    您应该在 Facebook 上注册一个应用程序才能使用 Facebook 登录。导航到 http://developers.facebook.com

    创建一个应用程序。您将获得一个应用程序ID和应用程序密码。将其用作appid,appsecret

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      相关资源
      最近更新 更多