Facebook SDK .NET - (#200)用户尚未授权应用程序执行此操作 [英] Facebook SDK .NET - (#200) The user hasn't authorized the application to perform this action
问题描述
我正在尝试从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
{
动态结果= facebookClient.Get(oauth / access_token,新
{
client_id = appId,
client_secret = appSecret,
grant_type =client_credentials,
redirect_uri = Request.Url.AbsoluteUri,
code = Request [code]
});
facebookClient.AccessToken = result.access_token;
//存储访问令牌
}
发送消息:
protected void PublishMessage(string message)
{
FacebookClient client = new FacebookClient(AccessToken);
client.AppId = ApplicationId;
client.AppSecret = ApplicationSecret;
动态参数= new ExpandoObject();
parameters.message = message;
client.Post(PageName +/ feed,参数);
}
我接受以下Facebook提示,以确保该应用可以访问: p>
在我的Facebook个人资料设置中,应用程序如下所示:
我正在使用Facebook SDK for .NET v6.4.2(最新版本)。
这可能是一个愚蠢的问题,但您是否从您的访问令牌请求中丢失了请求代码?不应该这样吗?
动态结果= facebookClient.Get(oauth / access_token,new
{
client_id = appId,
client_secret = appSecret,
grant_type =authorization_code
redirect_uri = Request.Url.AbsoluteUri,
code = Request [code]
});
修改刚刚意识到,使用不同的grant_type时,请求代码:)
I am trying to post a message to a Facebook page from a C# web application. I am getting the following exception thrown on calling FacebookClient.Post(...)
:
FacebookOAuthException (OAuthException - #200) (#200) The user hasn't authorized the application to perform this action
Code:
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
}
Sending a message:
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);
}
I accept the following Facebook prompts to ensure that the app has access:
And in my Facebook profile settings, the app looks like this:
I am using the Facebook SDK for .NET v6.4.2 (the latest).
This may seem a silly question, but aren't you missing the Request code from your access token request? Shouldn't it be like this?
dynamic result = facebookClient.Get("oauth/access_token", new
{
client_id = appId,
client_secret = appSecret,
grant_type = "authorization_code"
redirect_uri = Request.Url.AbsoluteUri,
code = Request["code"]
});
Edit Just realized, you have to use a different grant_type when using the request code :)
这篇关于Facebook SDK .NET - (#200)用户尚未授权应用程序执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!