C#&;Facebook API

C#&;Facebook API,c#,facebook,C#,Facebook,我目前正在使用Facebook API和C 我要做的是将图像上传到事件中 我试过两种方法,但似乎都不管用。谁能看一下吗 方法1 Dictionary<string, string> args = new Dictionary<string, string>(); string source = "@test.jpg"; string relpath = "/1234456789/photos"; args.A

我目前正在使用Facebook API和C

我要做的是将图像上传到事件中

我试过两种方法,但似乎都不管用。谁能看一下吗

方法1

        Dictionary<string, string> args = new Dictionary<string, string>();
        string source = "@test.jpg";
        string relpath = "/1234456789/photos";
        args.Add("message", "sssssss");
        args.Add("access_token", api.AccessToken);
        args.Add("source", source);
        api.Post(relpath, args);
方法3

        WebClient client = new WebClient();

        byte[] responseBinary = client.UploadFile("http://localhost:61689/Widgets/test2.aspx", "POST", @"C:\test.jpg");

        string response = Encoding.UTF8.GetString(responseBinary);

        Dictionary<string, string> args = new Dictionary<string, string>();

        string relpath = "https://graph.facebook.com/me/picture";
        args.Add("message", "sssssss");
        args.Add("access_token", GetAccessToken(code));
        args.Add("source", response); 

        api.Post(relpath, args);
WebClient=newWebClient();
字节[]responseBinary=client.UploadFile(“http://localhost:61689/Widgets/test2.aspx“,”POST“,@“C:\test.jpg”);
字符串响应=Encoding.UTF8.GetString(responseBinary);
Dictionary args=新字典();
字符串路径=”https://graph.facebook.com/me/picture";
参数添加(“消息”、“SSS”);
args.Add(“访问令牌”,GetAccessToken(代码));
参数添加(“源”,响应);
api.Post(relpath,args);
在方法3中,我试图创建响应并编写它。我收到了400个错误的请求


图像“test.jpg”当前位于我的网站根目录中,与调用它的页面相同。

嘿,Robert,不确定这是否是导致它的原因,但在示例1中,看起来您试图在jpg名称上使用字符串文字,但如果是这样,@符号需要在引号之外

@“早上好”//a字符串文字


看起来您只是在传递要上载的照片的文件名。您使用的是从磁盘读取实际照片内容的库吗?如果没有,您需要自己完成,并将内容写入请求


将照片内容写入请求的格式将取决于您正在写入的API的期望值(多部分等)。

当您说它不工作时,是否有任何错误?方法1的400个错误请求,方法2刚刚通过,但我在facebook上没有得到任何图像。希望这能有所帮助。以下问题可能会有所帮助:。这是一个不同的SDK,它应该只是一个标准帖子,但不起作用。将继续查找,或者必须在链接中实现sdk。干杯,我明白了。提示:当直接回复未提问或未提供答案的其他用户的评论时,请包括他们的@username,他们将得到通知。谢谢。这就是方法2试图做的。@Robert-在方法2中,我看不出你实际上在哪里写文件内容。我看到写文件名,但实际上没有写文件内容。
        WebClient client = new WebClient();

        byte[] responseBinary = client.UploadFile("http://localhost:61689/Widgets/test2.aspx", "POST", @"C:\test.jpg");

        string response = Encoding.UTF8.GetString(responseBinary);

        Dictionary<string, string> args = new Dictionary<string, string>();

        string relpath = "https://graph.facebook.com/me/picture";
        args.Add("message", "sssssss");
        args.Add("access_token", GetAccessToken(code));
        args.Add("source", response); 

        api.Post(relpath, args);