我正在开发的C#应用程序,管理脸书上的粉丝页面,这使用脸书C#软件开发工具包。我遇到了两个问题,一个是在墙上发布消息,另一个是在粉丝页面上创建活动。
有没有可能在粉丝页面墙上以粉丝页面而不是管理员用户的身份发布消息?
我可以以编程方式在粉丝页面上创建事件(不是作为管理员,而是作为粉丝页面)使用脸书C# SDK?
我看了一些其他SDK的教程,比如Facebook、PHP、SDK。PHP允许创建事件作为粉丝页面,但对于C# SDK,创建事件不会给出任何结果。
发布于 2011-03-09 00:00:34
发布消息需要授予账号权限,并通过/me/ manages_pages的结果向粉丝页账号获取访问令牌。
下面是我用来将消息本身发布到粉丝页面的方法:
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);发布于 2011-04-22 13:06:32
好吧,我刚刚遇到了完全一样的事情。出于我的目的,我授权一个应用程序发布到FB的粉丝页面作为粉丝页面。因此,我可以有多个用户可以访问应用程序,但不能访问粉丝页面,发布为粉丝页面。它可以满足我的需求。
无论如何,下面是我如何使用C# Facebook SDK BetaV5.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);发布于 2011-06-16 02:17:27
我想感谢你的帖子,它真的很有帮助。对我来说,它仍然在我的Facebook页面上以我的身份发布(而不是作为页面)。我想这就是我获得令牌的方式。不过,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
https://stackoverflow.com/questions/5231827
复制相似问题