我正在开发使用Facebook C#SDK在Facebook上管理粉丝页面的C#应用程序。我遇到了两个问题,一个是关于在墙上发布消息,另一个是关于在粉丝页面上创建事件。
是否可以在粉丝页面墙上发布消息作为粉丝页面而不是管理员用户?
我可以使用Facebook C#SDK以编程方式在粉丝页面上创建活动(不是作为管理员,而是作为粉丝页面)吗?
我浏览了其他SDK的其他SDK教程,例如Facebook PHP SDK。 PHP SDK允许将事件创建为粉丝页面,但在C#SDK的情况下,创建事件不会产生任何结果。
答案 0 :(得分:7)
好的,我刚刚碰到了同样的事情。为了我的目的,我正在授权一个应用程序发布到FB粉丝页面作为粉丝页面。因此,我可以让多个用户访问该应用程序,但不能访问粉丝页面,将其作为粉丝页面发布。它适用于我的要求。
无论如何,这是我使用C#Facebook SDK Beta V5.0.9的方式。 第一步,确保您尝试发布的用户帐户能够发布到粉丝页面,并且有权通过应用程序进行发布。
其中大部分内容与VorTechS相似,只是对其进行了一些澄清。
Dictionary<string,string> fbParams = new Dictionary<string,string>();
fbParams["message"] = Title;
fbParams["caption"] = string.Empty;
fbParams["description"] = string.Empty;
fbParams["req_perms"] = "publish_stream";
fbParams["scope"] = "publish_stream";
//Initialize Your Facebook Client in the manner that suits you, I did it by supplying a saved access token from a single users
FacebookWebClient fbClient = new FacebookWebClient(<YOUR_ACCOUNT_ACCESS_TOKEN>);
//Get the listing of accounts associated with the user
dynamic fbAccounts = fbClient.Get("/me/accounts");
//Loop over the accounts looking for the ID that matches your destination ID (Fan Page ID)
foreach (dynamic account in fbAccounts.data) {
if (account.id == <DESTINATION_ID_OF_YOUR_FAN_PAGE>) {
//When you find it, grab the associated access token and put it in the Dictionary to pass in the FB Post, then break out.
fbParams["access_token"] = account.access_token;
break;
}
}
//Then pass your destination ID and target along with FB Post info. You're Done.
dynamic publishedResponse = fbClient.Post("/" + <DESTINATION_ID_OF_YOUR_FAN_PAGE> + "/feed", fbParams);
答案 1 :(得分:1)
要发布消息,您需要授予manages_pages权限,并使用“/ me / accounts”的结果从粉丝页面的帐户中获取访问令牌。
以下是我用于将消息本身发布到粉丝专页的内容:
var dicParams = new Dictionary<string, object>();
dicParams["message"] = stSmContentTitle;
dicParams["caption"] = string.Empty;
dicParams["description"] = string.Empty;
dicParams["name"] = smContent.CmeUrl;
dicParams["req_perms"] = "publish_stream";
dicParams["scope"] = "publish_stream";
// Get the access token of the posting user if we need to
if (destinationID != this.FacebookAccount.UserAccountId)
{
dicParams["access_token"] = this.getPostingUserAuthToken(destinationID);
}
publishResponse = this.FacebookConnection.Post("/" + destinationID + "/feed", dicParams);
答案 2 :(得分:1)
我想感谢你的帖子,这真的很有帮助。对我来说,它仍然在我的Facebook页面上发布为ME(而不是页面)。我认为这只是我获得令牌的方式。虽然,foreach循环对我不起作用。所以,我这样做了:
public void postFacebook(object sender, EventArgs e)
{
//You will get your "myAccessToken" at this adress:
//https://www.facebook.com/dialog/oauth?client_id=<YOUR_APP_ID>&redirect_uri=<THE_PAGE_YOU_WILL_RECEIVE_YOUR_TOKEN_AT>&scope=offline_access,manage_pages,publish_stream&response_type=token
string myAccessToken = "<IN_THE_RETURNED_URL_BELOW>";
string myPageId = "<YOUR_FAN_PAGE_ID>";
Dictionary<string,string> fbParams = new Dictionary<string,string>();
fbParams["message"] = "Testing 1 2 test";
fbParams["caption"] = string.Empty;
fbParams["description"] = string.Empty;
fbParams["req_perms"] = "publish_stream";
fbParams["scope"] = "publish_stream";
//Initialize Your Facebook Client in the manner that suits you, I did it by supplying a saved access token from a single users
Facebook.FacebookAPI fbClient = new Facebook.FacebookAPI(myAccessToken);
//Get the listing of accounts associated with the user
var fbAccounts = fbClient.Get("/me/accounts");
//Loop over the accounts looking for the ID that matches your destination ID (Fan Page ID)
foreach (var account in fbAccounts.Dictionary["data"].Array)
{
if (account.Dictionary["id"].String == myPageId)
{
//When you find it, grab the associated access token and put it in the Dictionary to pass in the FB Post, then break out.
fbParams["access_token"] = account.Dictionary["access_token"].String;
//Update the Access token (to post as the page). If you don't it will post as YOUR personal name.
fbClient.AccessToken = fbParams["access_token"];
break;
}
}
//Then pass your destination ID and target along with FB Post info. You're Done.
dynamic publishedResponse = fbClient.Post("/" + myPageId + "/feed", fbParams);
}
顺便说一下,你需要这个sdk:SDK
答案 3 :(得分:1)
在MVC4和C#SDK中,这实现了我的目标
[FacebookAuthorize("publish_stream")]
public ActionResult PostNotification(FacebookContext context)
{
var dicParams = new Dictionary<string, object>();
dicParams["message"] = "đang tập code cho facebook ~@@";
dicParams["caption"] = "bbbbb";
dicParams["description"] = "cccccc";
dicParams["name"] = "http://www.facebook.com";
dicParams["req_perms"] = "publish_stream";
dicParams["scope"] = "publish_stream";
string destinationID = context.UserId;
context.Client.Post("/" + destinationID + "/feed", dicParams);
return RedirectToAction("Index");
}