如何发布从.NET Facebook页面墙 [英] how to post to facebook page wall from .NET
问题描述
我创建Facebook页面。
我没有申请的秘密,也没有访问令牌。
I've created Facebook page. I have no application secret and no access token.
我要张贴到这个网页从我的.NET桌面应用程序。
我该怎么办呢?任何人都可以请帮助,我在哪里可以得到访问令牌呢?
I want to post to this page from my .NET desktop application. How can I do it? Can anyone help please, where can I get access token for this?
我应该创建一个新的Facebook应用程序?如果是的话,我怎么能授予权限到这个应用程序上发布页面的墙上
Should I create a new Facebook Application? If yes, how can I grant permissions to this application to post on page's wall?
UPD1:
我没有网站。
我需要公司从.NET桌面应用程序的消息发布到公司的Facebook页面。
我只有登录/密码的Facebook页面的帐户
UPD1: I have no website. I need to post company's news from .NET desktop application to company's Facebook page. All I have is Login/Password for Facebook Page Account.
UPD2:
我创建Facebook应用程序。随着的AppID / SecretKey的。我能得到访问令牌。但是......
我怎样授予权限张贴到页面的墙?
UPD2: I've created Facebook Application. With AppID/SecretKey. I can get access token. But... How can I grant permissions to post to page's wall?
(OAuthException)(#200)用户不是招'T授权执行此操作的应用程序
推荐答案
我已经创建出一个视频教程如何在这个位置上做到这一点:
I have created a video tutorial showing how to do this at this location:
的 http://www.markhagan.me/Samples/Grant-Access-And-Post-As-Facebook-User-ASPNet
您会注意到,在我的例子中,我要求双方publish_stream和manage_pages。这使你可以还张贴在其用户是一个管理页面。下面是完整的代码:
You will notice that, in my example, I am asking for both "publish_stream" and "manage_pages". This let's you also post on pages of which that users is an admin. Here is the full 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;
namespace FBO
{
public partial class facebooksync : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CheckAuthorization();
}
private void CheckAuthorization()
{
string app_id = "374961455917802";
string app_secret = "9153b340ee604f7917fd57c7ab08b3fa";
string scope = "publish_stream,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 = 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);
client.Post("/me/feed", new { message = "markhagan.me video tutorial" });
}
}
}
}
这篇关于如何发布从.NET Facebook页面墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!