我正在尝试从 C# Web 应用程序向 Facebook 页面发布消息。我在调用时收到以下异常FacebookClient.Post(...)
:
FacebookOAuthException (OAuthException - #200) (#200) 用户尚未授权应用程序执行此操作
代码:
var facebookClient = new FacebookClient();
facebookClient.AppId = appId;
facebookClient.AppSecret = appSecret;
if (Request["code"] == null)
{
var authUrl = facebookClient.GetLoginUrl(new
{
client_id = appId,
client_secret = appSecret,
scope = "publish_stream",
redirect_uri = Request.Url.AbsoluteUri
});
Response.Redirect(authUrl.AbsoluteUri);
}
else
{
dynamic result = facebookClient.Get("oauth/access_token", new
{
client_id = appId,
client_secret = appSecret,
grant_type = "client_credentials",
redirect_uri = Request.Url.AbsoluteUri,
code = Request["code"]
});
facebookClient.AccessToken = result.access_token;
// Store access token
}
发送消息:
protected void PublishMessage(string message)
{
FacebookClient client = new FacebookClient(AccessToken);
client.AppId = ApplicationId;
client.AppSecret = ApplicationSecret;
dynamic parameters = new ExpandoObject();
parameters.message = message;
client.Post(PageName + "/feed", parameters);
}
我接受以下 Facebook 提示以确保应用程序具有访问权限:
在我的 Facebook 个人资料设置中,该应用程序如下所示:
我正在使用 Facebook SDK for .NET v6.4.2(最新)。