使用Facebook SDK .net 2015发布到组墙

时间:2015-10-13 15:28:42

标签: facebook facebook-graph-api sdk

似乎现在没有办法允许通过未经审核的新应用发布到Facebook用户组。

我创建了一个应用程序,其中包含可用于公众的实时功能,以及对电子邮件,public_profile,user_friends的批准。

我正试图在我创建的一个小组的墙上张贴,我是一名管理员。

现在,在启动我的代码时,我得到了令人讨厌的“OAuthException - #200)(#200)没有足够的权限发布到目标......”异常。

完美地发布我的墙...

public class HomeController : Controller
{

   private const  long GroupId = 15473890820xxxx;
    //
    // GET: /Home/
    public ActionResult Index(string code)
    {
        ViewBag.Message = "Welcome to Facebook App Demo!";

        //user denied permissions on Facebook. 
        if (Request["error_reason"] == "user_denied")
        {
            //this is not implemented. For reference only.
            return RedirectToAction("LogOn", "Account");
        }

        if (string.IsNullOrEmpty(code))
        {
            ViewBag.Error = "There was an error while loggin into Facebook. Please try again later.";
            return RedirectToAction("LogOn", "Account");
        }

        var fb = new FacebookClient();
        dynamic result = fb.Post("oauth/access_token", new
        {

            client_id = "93199615018xxxx",                
            client_secret = "2089ae4447877e7388500b844235xxxx",               
            redirect_uri = "http://localhost:13301/",
            code = code
        });

        var appToken = result.access_token as string;

        // update the facebook client with the access token so 
        // we can make requests on behalf of the user
        fb.AccessToken = appToken;

        //get extended App/User Token
        dynamic result2  = fb.Get("oauth/access_token", new
        {

            client_id = "93199615018xxxx"

            client_secret = "2089ae4447877e7388500b844235xxxx",

            grant_type="fb_exchange_token",
            fb_exchange_token = appToken,
           // code = code
        });

        var extendedAppToken = result2.access_token as string;
        //generate Extended User Token (valid for 60 days)

        Session["Facebooktoken"] = extendedAppToken; 

        dynamic me = fb.Get("me/accounts");

        var response = fb.Get("/me/accounts?access_token=" + extendedAppToken) as JsonObject;

        return View(me);

    }

    [HttpPost]
    public ActionResult Index(FormCollection collection) //rename to PostWall
    {
        ViewBag.Message = "Welcome to Facebook App Demo!";

        // Post to the wall..
        try
        {
            if (Session["Facebooktoken"] != null)
            {
                string message = collection["txtPost"].ToString();
                FacebookClient client = new FacebookClient(Session["Facebooktoken"].ToString());

                dynamic result = client.Post(GroupId+"/feed", new
                {
                    message = message
                });

                ViewBag.SaveMessage = "Successfuly Post on your wall : " + result.id;
            }
            else
            {
                return RedirectToAction("LogOn", "Account");
            }
        }
        catch (Exception ex)
        {
            ModelState.AddModelError("", ex.Message);
        }

        return View();
    }

    public ActionResult About()
    {
        return View();
    }
}
public class AccountController : Controller
{
    //
    // GET: /Account/

    public ActionResult LogOn()
    {
        return View();
    }

    [HttpPost]
    public ActionResult LogOn(LogOnModel model, string returnUrl)
    {

        var facebookAppId = "93199615018xxxx";

        var facebookAppSecret = "2089ae4447877e7388500b844235xxxx";

        var facebookRedirectUrl = "http://localhost:13301/";
        //
        var facebookScope = "email,publish_pages,publish_actions,manage_pages,user_managed_groups,user_hometown,user_website";

        if (facebookAppId != null && facebookAppSecret != null && facebookRedirectUrl != null && facebookScope != null)
        {
            var url = string.Format(@"https://www.facebook.com/dialog/oauth/?client_id={0}&redirect_uri={1}&scope={2}", facebookAppId, facebookRedirectUrl, facebookScope);

            Response.Redirect(url, true);
        }

        return this.RedirectToAction("Index", "Home");
    }

}

有关如何为上述功能设置测试环境的任何线索,而无需额外建立一个必须由Facebook管理员审核的完全成熟的应用程序?我看过测试应用程序和用户的版本,但也没有组。

非常感谢提前

1 个答案:

答案 0 :(得分:0)

达伦,谢谢你的考虑。这似乎是由于我的隐私限制,我无法得到我的个人帐户的任何组信息。无论是以编程方式,还是在Facebooks Graph API Explorer中手动完成。

它终于在商业(粉丝)' Page'获得一个“长寿”的简介。 Facebook中的页面访问令牌Access Token Debuger

是,已启用user_managed_groups和publish_actions。