首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tweetinvi:向PublishTweetAsync方法添加凭据

Tweetinvi:向PublishTweetAsync方法添加凭据
EN

Stack Overflow用户
提问于 2022-05-29 13:33:52
回答 1查看 78关注 0票数 0

我在推特上有一个很高的发展账户。

我正在用以下代码测试特温维

代码语言:javascript
复制
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);
}

我得到了一个错误:

代码语言:javascript
复制
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.

在这一行代码中:

代码语言:javascript
复制
var tweet = await userClient.Tweets.PublishTweetAsync("Hello tweetinvi world!");

如何将凭据添加到PublishTweetAsync调用中?

或者,还有另一种方法可以在不使用PublishTweetAsync的情况下发布带有凭据的tweet。

更新

由于安迪·派珀的回答,我不得不说代码是编译的,所以TwitterClient的所有参数都有一个值(当然,我不会在这里共享它们),我可以在这里得到user

代码语言:javascript
复制
var user = await userClient.Users.GetAuthenticatedUserAsync();

我也做到了这一点:

但是我不知道该在回调URI中放什么。

EN

回答 1

Stack Overflow用户

发布于 2022-05-29 14:34:24

答案在您的代码…中。

代码语言:javascript
复制
// we create a client with your user's credentials
    var userClient = new TwitterClient(ConsumerKey, ConsumerSecret, AccessToken, AccessTokenSecret);

您需要在代码中定义要传递给TwitterClient实例的值。您还需要确保有一个访问V1.1API(提升访问权限)的应用程序才能使用这段代码,因为它不适用于v2。

最后,您应该检查您的应用程序是否具有读写权限,并且您的访问令牌和秘密是使用这些权限生成的。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72424101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档