Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将帖子发送到Facebook页面_C#_Facebook Graph Api_Oauth - Fatal编程技术网

C# 将帖子发送到Facebook页面

C# 将帖子发送到Facebook页面,c#,facebook-graph-api,oauth,C#,Facebook Graph Api,Oauth,我有一个c#asp.net web应用程序 我通过他们的javascript sdk使用facebook登录,它会登录 现在我有了一个简单的WYSIWYG编辑器,任何添加的内容都应该发布在登录用户的facebook页面上 代码如下: string FacebookApiId = "952214336368241"; string FacebookApiSecret = "fb2213d66523c8cb0bc99306f46ee457"; string accessToke

我有一个c#asp.net web应用程序

我通过他们的javascript sdk使用facebook登录,它会登录

现在我有了一个简单的WYSIWYG编辑器,任何添加的内容都应该发布在登录用户的facebook页面上

代码如下:

   string FacebookApiId = "952214336368241";

   string FacebookApiSecret = "fb2213d66523c8cb0bc99306f46ee457";

   string accessToken = GetAccessToken(FacebookApiId, FacebookApiSecret);

   PostMessage(accessToken, "My message");


private string GetAccessToken(string apiId, string apiSecret)
{
    string AuthenticationUrlFormat = "https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials&scope=manage_pages,offline_access,publish_stream";

    string accessToken = string.Empty;
    string url = string.Format(AuthenticationUrlFormat, apiId, apiSecret);

    WebRequest request = WebRequest.Create(url);
    WebResponse response = request.GetResponse();

    using (Stream responseStream = response.GetResponseStream())
    {
        StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
        String responseString = reader.ReadToEnd(); // this gives me {"access_token":"952214336368241|McqSGYIMU1eYBZ1zGydWj9hu6Bt","token_type":"bearer"}           

        NameValueCollection query = HttpUtility.ParseQueryString(responseString);

        accessToken = query["access_token"]; // This line throws error
    }

    //if (accessToken.Trim().Length == 0)
        //throw new Exception("There is no Access Token");

    return "952214336368241|McqSGYIMU1eYBZ1zGydWj9hu6B"; // hard-coded to get it working;
}

private void PostMessage(string accessToken, string v)
{
    try
    {
        FacebookClient facebookClient = new FacebookClient(accessToken);

        dynamic messagePost = new ExpandoObject();
        messagePost.access_token = accessToken;          
        messagePost.message = v;            
        var result = facebookClient.Post("/[user id]/feed", messagePost);
    }
    catch (FacebookOAuthException ex)
    {
        //handle something
    }
    catch (Exception ex)
    {
        //handle something else
    }
}
这会引发错误:

{“(OAutheException-#803)(#803)您请求的某些别名不存在:[user id]”}

我甚至写了我的facebook emailid而不是[user id],但它仍然不起作用,并给我错误:

消息:“(OAutheException-#2500)必须使用活动访问令牌来查询有关当前用户的信息。”

谁能告诉我如何删除此错误。

  • 代码非常古老,
    离线访问
    发布流
    多年来已不复存在
  • 您必须使用具有
    publish\u pages
    权限的页面令牌,才能使用API发布到您的页面
  • 您可以使用“我/订阅源”或“页面id/订阅源”,但不能使用电子邮件
有关令牌以及如何生成令牌的信息:


编程前在API资源管理器中尝试以下内容:

永远不要公开你的应用程序机密…尽快使其无效/刷新。它被称为秘密是有原因的。另外,看起来你有两个不同的应用程序秘密。请确保您完全理解发生了什么,不要只是复制/粘贴(非常旧的)代码,并假设它会以某种方式工作。感谢您的答复,非常感谢。我的应用程序处于开发模式。我需要提交验证文件才能通过API在我的facebook页面上发布消息吗?不是为了测试,但只有在你不“上线”的情况下,新帖子才会显示给你(而不是普通用户)使用app.luschn-当我单击“添加权限和功能”并请求“发布页面”时,会显示“继续”按钮,要求我进行说明和验证。。那我该怎么办?你为什么要这么做?您是否已经对项目进行了编程和测试?我说“不用于测试”,如果你甚至没有编写任何程序,你就不需要经历审查过程。那么facebook能评论什么呢?上线意味着付费?