简体   繁体   English

Tweetinvi:向 PublishTweetAsync 方法添加凭据

[英]Tweetinvi: add credentials to the PublishTweetAsync method

I have an elevated development account in Twitter.我在 Twitter 上有一个高级开发帐户。

I'm testing Tweetinvi with this code:我正在使用以下代码测试Tweetinvi

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);
}

And I get this error:我得到这个错误:

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.

On this line of code:在这行代码上:

var tweet = await userClient.Tweets.PublishTweetAsync("Hello tweetinvi world!");

How can I add the credentials to the PublishTweetAsync call?如何将凭据添加到PublishTweetAsync调用?

Or maybe, there is another way to publish a tweet with credentials without using PublishTweetAsync ?或者,还有另一种方法可以在不使用PublishTweetAsync的情况下发布带有凭据的推文?

UPDATE更新

Due to the answer of Andy Piper , I have to say that the code compiles, so all the arguments for TwitterClient has a value (of course, I'm not going to share them here), and I can get the user here:由于Andy Piper的回答,不得不说代码可以编译,所以TwitterClient的所有参数都是有值的(当然这里我不打算分享),我可以在这里获取user

var user = await userClient.Users.GetAuthenticatedUserAsync();

I have also enabled this:我也启用了这个: 在此处输入图像描述

But I don't know what to put in the Callback URI.但我不知道在回调 URI 中放什么。

The answer is in your code…答案在您的代码中……

// we create a client with your user's credentials
    var userClient = new TwitterClient(ConsumerKey, ConsumerSecret, AccessToken, AccessTokenSecret);

You need to have the values defined in your code to pass in to the TwitterClient instance.您需要在代码中定义值才能传递给TwitterClient实例。 You also need to ensure that you have an app with access to the v1.1 API (elevated access) to use this code, since it will not work with v2.您还需要确保您的应用程序可以访问 v1.1 API(提升访问权限)才能使用此代码,因为它不适用于 v2。

Finally, you should check that your app has read and write permissions and that your access token and secret were generated with these permissions.最后,您应该检查您的应用程序是否具有读取和写入权限,并且您的访问令牌和密码是使用这些权限生成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM