如何使用以下代码发布到其他人的个人资料

时间:2012-12-11 16:33:56

标签: c# facebook entity-framework-4.1

我有以下代码:

      public void CheckAuthorization()
    {

        string app_id = "";//Your id here
        string app_secret = "";//your secret key
        string scope = "publish_stream, manage_pages";

        if (Request["code"] == null)
        {

            Response.Redirect(string.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
               app_id, Request.Url.AbsoluteUri, scope));

        }
        else
        {
            Dictionary<string, string> tokens = new Dictionary<string, string>();
            string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
                app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret);


            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {


                StreamReader reader = new StreamReader(response.GetResponseStream());
                string vals = reader.ReadToEnd();
                foreach (string token in vals.Split('&'))
                {

                    tokens.Add(token.Substring(0, token.IndexOf("=")), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=")-1));

                }
            }

            string access_token=tokens["access_token"];
            var client = new FacebookClient(access_token);
            client.Post("me/feed", new { message="Hi"});



        }


    }

使用此代码,我可以使用

行发布到我的个人资料
        client.Post("me/feed", new { message="Hi"});

如何在其他个人资料上发帖?

1 个答案:

答案 0 :(得分:2)

试试这个:

client.Post("/PROFILE_ID/feed", new { message="Hi"});

更多信息:https://developers.facebook.com/docs/reference/api/#publishing