gpt4 book ai didi

c# - 如何将照片发布到 Facebook 页面提要 - 不是由其他人发布的

转载 作者:行者123 更新时间:2023-12-02 05:00:34 25 4
gpt4 key购买 nike

我已经安装了facebook sdk

现在我可以用下面的代码像这样发帖了

enter image description here

发布上述消息的代码

        FacebookClient myClient = new FacebookClient(srAcceToken);
var dicParams = new Dictionary<string, object>();
dicParams["message"] = "trial message";
dicParams["caption"] = string.Empty;
dicParams["description"] = string.Empty;
dicParams["name"] = "deneme 123";
dicParams["req_perms"] = "publish_stream";
dicParams["scope"] = "publish_stream";
dicParams["access_token"] = srAcceToken;
var publishResponse = myClient.Post("/" + srPageId + "/feed", dicParams);

现在当我想发布图片时出现问题。当我使用下面的代码发帖时,我得到了这张图片

enter image description here

获取上述结果的代码

            var mediaObject = new FacebookMediaObject
{
ContentType = "image/jpeg",
FileName = "pokemon.jpg"
}.SetValue(File.ReadAllBytes(Imagepath));

FacebookClient myClient = new FacebookClient(srAcceToken);
var dicParams = new Dictionary<string, object>();
dicParams["message"] = "trial message";
dicParams["caption"] = string.Empty;
dicParams["description"] = string.Empty;
dicParams["name"] = "deneme 123";
dicParams["req_perms"] = "publish_stream";
dicParams["scope"] = "publish_stream";
dicParams["source"] = mediaObject;
dicParams["type"] = "normal";
dicParams["access_token"] = srAcceToken;
var publishResponse = myClient.Post("/" + srPageId + "/photos", dicParams)

但我想发布如下图片 - 我该怎么做?

c# 4.5 - 使用最新的 facebook sdk 谢谢

enter image description here

最佳答案

希望这段简短的代码对您有所帮助

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);

===================================

fbParams["access_token"] = account.access_token;

这一行会让你获得在这个页面上写东西的权限

关于c# - 如何将照片发布到 Facebook 页面提要 - 不是由其他人发布的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17157808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com