我正在使用来自Facebook C#SDK的示例。每次运行代码CanvasAuthorizer.Authorize()
时,它总是返回false
。我在app_id
文件中指定了web.config
和密钥。并且还有扩展许可。
<add key="extendedPermissions" value="user_about_me,publish_stream"/>
这是我的代码:
public partial class MForm : System.Web.UI.Page
{
private CanvasAuthorizer _canvasAuthorizer;
protected CanvasAuthorizer CanvasAuthorizer
{
get
{
if (_canvasAuthorizer == null)
{
var extendedPermissions = ConfigurationManager.AppSettings["extendedPermissions"].Split(',');
_canvasAuthorizer = new CanvasAuthorizer();
}
return _canvasAuthorizer;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (CanvasAuthorizer.Authorize())
{
var fb = new FacebookWebClient();
dynamic me = fb.Get("me");
imgProfilePic.ImageUrl = string.Format("https://graph.facebook.com/{0}/picture", me.id);
lblName.Text = me.name;
lblFirstName.Text = me.first_name;
lblLastName.Text = me.last_name;
}
else
{
}
}
protected void btnPostToWall_Click(object sender, EventArgs e)
{
if (CanvasAuthorizer.Authorize())
{
var fb = new FacebookWebClient();
dynamic parameters = new ExpandoObject();
parameters.message = txtMessage.Text;
try
{
dynamic id = fb.Post("me/feed", parameters);
lblPostMessageResult.Text = "Message posted successfully";
txtMessage.Text = string.Empty;
}
catch (FacebookApiException ex)
{
lblPostMessageResult.Text = ex.Message;
}
}
}
}