Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在twitter c中发布帐户/更新_profile_图像_C#_.net - Fatal编程技术网

C# 如何在twitter c中发布帐户/更新_profile_图像

C# 如何在twitter c中发布帐户/更新_profile_图像,c#,.net,C#,.net,我无法实现Twitter的[update profile image]方法。是否有人拥有将图像作为原始多艺术数据传递到Twitter API的示例代码?直接使用API进行此操作非常简单,只需要对API端点执行POST请求,并将图像的base64作为图像查询字符串的值追加 职位 读取图像文件并将其转换为base64也很简单 string base64Data = Convert.ToBase64String(File.ReadAllBytes("image.jpg")); string url=

我无法实现Twitter的[update profile image]方法。是否有人拥有将图像作为原始多艺术数据传递到Twitter API的示例代码?

直接使用API进行此操作非常简单,只需要对API端点执行POST请求,并将图像的base64作为图像查询字符串的值追加

职位

读取图像文件并将其转换为base64也很简单

string base64Data = Convert.ToBase64String(File.ReadAllBytes("image.jpg"));
string url= "https://api.twitter.com/1.1/account/update_profile_image.json?image=" + base64Data
更复杂的部分首先是针对API进行身份验证。假设您已经这样做了,那么上面的代码将满足您的需求

如果没有,您需要查看库或SDK,如LinqToTwitter。维基上有很多例子

如果要手动编写请求代码,请参阅API文档了解如何构造请求:

使用Tweetinvi:


Twitter的API文档中列出了多种语言的库:

请解释您尝试了什么。发布您的代码,etci想使用twitter rest api更改我的twitter配置文件图像twitter api有几个版本。我假设您使用的是SDK,如果是,是什么版本。如果不是,您是否正在编写原始套接字来访问api?使用TCP客户端、WebClient、HttpWebRequests。你需要提供更多关于你具体想做什么以及你有什么问题的信息。我正在使用这个api从如何使用它看我的答案。您只需将图像转换为base64并将其作为图像查询字符串的值附加。答案中有c代码可以获取此值,或者您可以使用在线base64工具。如何调用此api?我的代码格式中是否有任何格式?这不是使用库或SDK的工作手册。我过去使用过LinqToTwitter。否则ifMethod==POST&&string.IsNullOrEmptyjsonPath{request.ContentType=application/x-www-form-urlencoded;}这样好吗
private class AuthCredentials
{
    public string ConsumerKey = "ConsumerKey";
    public string ConsumerSecret = "ConsumerSecret";
    public string AccessToken = "AccessToken";
    public string AccessTokenSecret = "AccessTokenSecret";
}


static void Main(string[] args)
{
    var creds = new AuthCredentials();
    Auth.SetUserCredentials(creds.ConsumerKey, creds.ConsumerSecret, creds.AccessToken, creds.AccessTokenSecret);
    var data = File.ReadAllText("myimage.jpg");
    Account.UpdateProfileImage(data);
}