我在推特上有一个很高的发展账户。
我正在用以下代码测试特温维:
private async Task ConnectToTwitter()
{
// we create a client with your user's credentials
var userClient = new TwitterClient(ConsumerKey, ConsumerSecret, AccessToken, AccessTokenSecret);
toolStripStatusLabel1.Text = "Connected";
// request the user's information from Twitter API
var user = await userClient.Users.GetAuthenticatedUserAsync();
labelUserName.Text = user.Name;
// publish a tweet
var tweet = await userClient.Tweets.PublishTweetAsync("Hello tweetinvi world!");
Console.WriteLine("You published the tweet : " + tweet);
}我得到了一个错误:
Reason : Unauthorized
Code : 401
Date : 29/05/2022 15:25:49 +02:00
URL : https://api.twitter.com/1.1/statuses/update.json?status=Hello%20tweetinvi%20world%21&tweet_mode=extended
Twitter documentation description : Unauthorized - Authentication credentials were missing or incorrect.在这一行代码中:
var tweet = await userClient.Tweets.PublishTweetAsync("Hello tweetinvi world!");如何将凭据添加到PublishTweetAsync调用中?
或者,还有另一种方法可以在不使用PublishTweetAsync的情况下发布带有凭据的tweet。
更新
由于安迪·派珀的回答,我不得不说代码是编译的,所以TwitterClient的所有参数都有一个值(当然,我不会在这里共享它们),我可以在这里得到user:
var user = await userClient.Users.GetAuthenticatedUserAsync();我也做到了这一点:

但是我不知道该在回调URI中放什么。
发布于 2022-05-29 14:34:24
答案在您的代码…中。
// we create a client with your user's credentials
var userClient = new TwitterClient(ConsumerKey, ConsumerSecret, AccessToken, AccessTokenSecret);您需要在代码中定义要传递给TwitterClient实例的值。您还需要确保有一个访问V1.1API(提升访问权限)的应用程序才能使用这段代码,因为它不适用于v2。
最后,您应该检查您的应用程序是否具有读写权限,并且您的访问令牌和秘密是使用这些权限生成的。
https://stackoverflow.com/questions/72424101
复制相似问题