gpt4 book ai didi

facebook-c#-sdk - 怎么把照片贴在墙上?

转载 作者:行者123 更新时间:2023-12-04 07:41:58 25 4
gpt4 key购买 nike

有没有人成功地将图片发布到当前用户的墙上?这不起作用,如果图片参数是现有的图片网址帖子不显示!我正在使用最新的 FB C# SDK 5.0.8 Beta ...

var args = new Dictionary<string, object>();
args["name"] = "My App";
args["link"] = @"http://apps.facebook.com/test/";
args["caption"] = "My Caption";
args["description"] = "My Description";
args["picture"] = @"http://www.test.com/test.jpeg";
args["message"] = "My Message";
args["actions"] = "";
FbClient.PostAsync(@"/me/feed", args);

最佳答案

这是我如何处理将照片发布到 Facebook 用户的墙上。 ImagePath 和 ImageName 是我传递给包含此代码的函数的字符串参数。

    var fbApp = new FacebookApp();
var auth = new CanvasAuthorizer(fbApp);

if (auth.IsAuthorized())
{

//Create a new dictionary of objects, with string keys
Dictionary<string, object> parameters = new Dictionary<string, object>();

string strDescription = txtDescription.Text;

//Add elements to the dictionary
if (string.IsNullOrEmpty(ImagePath) == false)
{
//There is an Image to add to the parameters
FacebookMediaObject media = new FacebookMediaObject
{
FileName = ImageName,
ContentType = "image/jpeg"
};

byte[] img = File.ReadAllBytes(ImagePath);
media.SetValue(img);

parameters.Add("source", media);
parameters.Add("message", strDescription);

try
{
dynamic result = fbApp.Api("/me/photos", parameters, HttpMethod.Post);

}
catch (Exception ex)
{
//handle error....
string strErr = ex.Message.ToString();
lblValidationMsg.Text = strErr;
}
}

}

关于facebook-c#-sdk - 怎么把照片贴在墙上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5500016/

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