如何使用C#没有游客发表于Facebook页面直接张贴? [英] how to post on directly at facebook page using C# not at visitor post?

查看:188
本文介绍了如何使用C#没有游客发表于Facebook页面直接张贴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我审阅这篇文章
如何张贴到Facebook页面墙从.NET 但它的Facebook页面上的工作后为游客职。
我想不是游客发表后页时间表的,我这个页面和应用程序的管理。
请给它的解决方案。

在这里我的code

 使用系统;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq的;
使用System.Net;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用Facebook的;
使用System.Dynamic;公共部分类Facebook的:System.Web.UI.Page
{
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        authontication();
    }
    私人无效authontication()
    {
        字符串APP_ID =************
        字符串app_secret =###################################;
        字符串范围=publish_actions,manage_pages        如果(请求[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,范围));
        }
        其他
        {
            字典<字符串,字符串>令牌=新词典<字符串,字符串>();            字符串的URL = string.Format(\"https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&$c$c={3}&client_secret={4}\",
            APP_ID,Request.Url.AbsoluteUri,范围,请求[code]的ToString(),app_secret)。            HttpWebRequest的要求= System.Net.WebRequest.Create(URL)为HttpWebRequest的;            使用(HttpWebResponse响应= request.GetResponse()作为HttpWebResponse)
            {
                StreamReader的读者=新的StreamReader(response.GetResponseStream());
                字符串瓦尔斯= reader.ReadToEnd();                的foreach(字符串令牌vals.Split('和;'))
                {
                    //meh.aspx?token1=steve&token2=jake& ...
                    tokens.Add(token.Substring(0,token.IndexOf(=)),
                        token.Substring(token.IndexOf(=)+ 1,token.Length - token.IndexOf(=) - 1));
                }
            }
            字符串的access_token =令牌[的access_token];
            VAR的客户=新FacebookClient(的access_token);            //动态参数=新ExpandoObject();
            字符串名称=sudhanshu;            名称+ =新数据;            client.Post(/ 1168908853153698 /饲料,新{消息=我的第一appProduct+名字+。});        }    }}


解决方案

您需要使用页面令牌,而不是一个用户令牌。确保它确实是一个页面令牌通过调试它: https://developers.facebook.com/工具/调试/的accessToken /

此外, publish_actions 是张贴的页面错误的权限,则需要使用 publish_pages

其他信息:

i refereed this post how to post to facebook page wall from .NET but it will work on facebook page to post as visitor post. and i want to post of page timeline not at visitor post and i am admin of this page and app. please give solution for it .

here in my code

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook;
using System.Dynamic;

public partial class facebook : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        authontication();
    }
    private void authontication()
    {
        string app_id = "**********************";
        string app_secret = "###################################";


        string scope = "publish_actions,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 = System.Net.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('&'))
                {
                    //meh.aspx?token1=steve&token2=jake&...
                    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);

            //dynamic parameters = new ExpandoObject();
            string name = "sudhanshu";

            name += " new data";

            client.Post("/1168908853153698/feed", new { message = "My first appProduct "+name+" ." });



        }

    }

}

解决方案

You need to use a Page Token, not a User Token. Make sure it really is a Page Token by debugging it: https://developers.facebook.com/tools/debug/accesstoken/

Also, publish_actions is the wrong permission to post as Page, you need to use publish_pages.

Additional information:

这篇关于如何使用C#没有游客发表于Facebook页面直接张贴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆