Rob*_*man 5 asp.net facebook facebook-graph-api
我有一个网站,我已注册为Facebook应用程序 - 我现在有一个应用程序ID.
我的网站是ASP.net C#.当用户点击按钮时,我希望它将预定义的消息发布到他们的墙上.我期待Facebook向用户提供登录对话框 - 他们登录并授予我的网站应用程序的发布权限.
有没有人有任何样本代码可以做到这一点?我想我需要使用图形API,但我见过的所有示例都使用PHP - 我对此一无所知.我正在寻找一个使用Java Script(我几乎什么都不知道)或C#(漂亮!)的例子.
*更新*
我设法得到access_token.现在我通过Facebook C#API拨打电话发布到墙上.我收到错误消息:
(#803)您请求的某些别名不存在:profile_id
我已经通过api代码,发现它正试图发布到以下地址:{ https://graph.facebook.com/PROFILE_ID/feed },帖子数据是:message = Sample + message + from + C%23 + SDK&=的access_token 199209316768200 | 2.1avFTZuDGR4HJ7jPFeaO3Q __ 3600.1302897600.1-100000242760733 |.R4DkNDf4JCb6B2F64n5TSQwBqvM
我很确定我的令牌应该有效.在请求访问令牌之前,我在应用程序授权请求中请求了publish_stream,如下所示:
Response.Redirect ("https://www.facebook.com/dialog/oauth?client_id=" + myAppId + "&redirect_uri=" + myURL + "&scope=publish_stream");
Run Code Online (Sandbox Code Playgroud)
实际发出请求的sdk代码如下:
private string MakeRequest(Uri url, HttpVerb httpVerb,
Dictionary<string, string> args)
{
if (args != null && args.Keys.Count > 0 && httpVerb == HttpVerb.GET)
{
url = new Uri(url.ToString() + EncodeDictionary(args, true));
}
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = httpVerb.ToString();
if (httpVerb == HttpVerb.POST)
{
string postData = EncodeDictionary(args, false);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] postDataBytes = encoding.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postDataBytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postDataBytes, 0, postDataBytes.Length);
requestStream.Close();
}
try
{
using (HttpWebResponse response
= request.GetResponse() as HttpWebResponse)
{
StreamReader reader
= new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();
}
}
Run Code Online (Sandbox Code Playgroud)
谁能看到我做错了什么?
非常感谢,
抢.
首先,您需要处理Authentication。您需要创建一个应用程序,并使用 OAuth 来获取访问令牌。身份验证指南中对此进行了全部描述。
要将某些内容发布到用户墙上,请查看“发布”下的图形 API。
首先,您可以使用Facebook 的 C# SDK
| 归档时间: |
|
| 查看次数: |
7014 次 |
| 最近记录: |