简体   繁体   English

从网站发布消息到Facebook墙

[英]Post message from Website to Facebook wall

I have a website made with ASP.NET webform .NET 4.5 C#. 我有一个使用ASP.NET Webform .NET 4.5 C#创建的网站。 This site contains a forum(homemade by me), parts of this forum needs to be posted to the specific facebook wall(made for this webpage). 该站点包含一个论坛(由我自制),该论坛的某些部分需要发布到特定的Facebook墙(针对此网页)。 What I need : 我需要的 :

  1. Post just created thread(message) from specific part of the forum to the corsponding facebook wall. 从论坛的特定部分将刚创建的主题(消息)发布到相应的Facebook墙上。

  2. Optional : Sync the forum thread on webpage with message/comments on the specific facebook page 可选:将网页上的论坛主题与特定facebook页面上的消息/评论同步

I have looked at these guides : http://www.codeproject.com/Articles/569920/Publish-a-post-on-Facebook-wall-using-Graph-API http://www.c-sharpcorner.com/UploadFile/raj1979/post-on-facebook-users-wall-using-Asp-Net-C-Sharp/ 我看过这些指南: http : //www.codeproject.com/Articles/569920/Publish-a-post-on-Facebook-wall-using-Graph-API http://www.c-sharpcorner.com/ UploadFile / raj1979 / post-on-facebook-users-wall-using-Asp-Net-C-Sharp /

But im not sure that this is really the solution for me? 但是我不确定这真的是我的解决方案吗? I have tried to follow the guide but it does not look the same. 我尝试按照指南进行操作,但看起来并不相同。

Edit : 编辑:

dynamic result;

        //https://developers.facebook.com/tools/explorer/
        //https://developers.facebook.com/tools/access_token/
        FacebookClient client = new FacebookClient(ConfigurationManager.AppSettings["FacebookAppToken"]);

        //result = client.Get("debug_token", new
        //{
        //    input_token = ConfigurationManager.AppSettings["FacebookAppToken"],
        //    access_token = ConfigurationManager.AppSettings["FacebookAppToken"]
        //});


        //result = client.Get("oauth/access_token", new
        //    {
        //        client_id = ConfigurationManager.AppSettings["FacebookAppId"],
        //        client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
        //        grant_type = "client_credentials",
        //        //redirect_uri = "http://www.MyDomain.net/",
        //        //code = ""
        //    });

        result = client.Get("oauth/access_token", new
        {
            client_id = ConfigurationManager.AppSettings["FacebookAppId"],
            client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
            grant_type = "client_credentials"
        });
        client.AccessToken = result.access_token;

        result = client.Post("[IdOfFacebookPage]/feed", new { message = "Test Message from app" });
        //result.id;
        result = client.Get("[IdOfFacebookPage]");

        return false;

Approach to post to a facebook wall: 发布到Facebook墙的方法:

  1. You need to register in facebook developer tools. 您需要在Facebook开发人员工具中注册。
  2. Create a app (fill a form). 创建一个应用程序(填写表格)。
  3. Download FGT 5.0.480 (Facebook graph toolkit) 下载FGT 5.0.480(Facebook图形工具包)
  4. Reference FGT dlls in your web application. 在您的Web应用程序中引用FGT dll。
  5. FGT has methods to post to facebook wall but needs appId. FGT有发布到Facebook墙的方法,但需要appId。
  6. Use the app id of your app created in step 2. 使用您在步骤2中创建的应用的应用ID。

To post to an user's wall through facebook, it is only possible through an app. 要通过Facebook发布到用户的墙上,只能通过一个应用程序。

Try this asp .net app, which will allow you to post in your wall: https://apps.facebook.com/aspdotnetsample/?fb_source=search&ref=br_tf 试试这个asp .net应用程序,它将允许您在墙上张贴: https : //apps.facebook.com/aspdotnetsample/?fb_source=search&ref=br_tf

This will allow you to envision what you need. 这将使您能够设想您所需要的。

Your app gets an appId with which you need to generate auth token. 您的应用会获取一个appId,您需要使用它来生成身份验证令牌。

Limitation: The user's wall where you want to post should have added the app created at step 2, this is compulsory and there is no work around. 限制:您要发布的用户墙应已添加在步骤2中创建的应用程序,这是强制性的,无法解决。

When the user accesses the app for the first time, it automatically asks for permission to post to wall--> the user needs to accept it. 当用户首次访问该应用程序时,它会自动请求发布到墙上的许可->用户需要接受该应用程序。

Hope this gives you an idea on how to go about doing this. 希望这会给您一个有关如何执行此操作的想法。

You can then post into the user's wall. 然后,您可以发布到用户的墙上。

For Banshee's below request using Facebook SDK for .NET: 对于Banshee的以下请求,使用适用于.NET的Facebook SDK:

userId - facebook user id, wall to post the message userId-Facebook用户ID,张贴消息的墙

This user should have added the app created by you in step 1 else it will say unauthorized access. 该用户应该已经在步骤1中添加了您创建的应用,否则会显示未授权访问。

dynamic messagePost = new ExpandoObject();
messagePost.picture = "http://www.stackoverflow.com/test.png";
messagePost.link = "http://www.stackoverflow.com";
messagePost.name = "This is a test name";

messagePost.caption = "CAPTION 1";
messagePost.description = "Test desc";
messagePost.message = "message"

var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new { 
client_id     = "app_id", 
client_secret = "app_secret", 
grant_type    = "client_credentials" 
});
fb.AccessToken = result.access_token;    

try
{
 var postId = fb.Post(userId + "/feed", messagePost);
}
catch (FacebookOAuthException ex)
{
  //handle oauth exception
}
catch (FacebookApiException ex)
{
  //handle facebook exception
}

You will need an extended token to publish to a wall.. Steps to get extended token is explained well by Banshee.. 您将需要一个扩展的令牌才能发布到墙上。Banshee很好地解释了获取扩展令牌的步骤。

Edit: How to get extended token by Banshee: Please follow this post 编辑:如何通过女妖获得扩展的令牌:请按照这篇文章

By creating a extended page token and use it to make the post everything works just fine. 通过创建扩展页面令牌并使用它来发布帖子,一切正常。 See this : How to get Page Access Token by code? 参见: 如何通过代码获取页面访问令牌?

Im surprised that this simple task was so hard to get running and that there was vary little help to get. 我很惊讶这个简单的任务很难执行,并且几乎没有什么帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM