2

I've been trying for days on this and think that the issue is somewhere with my developer account but thought I'd ask for advice here first before digging in there. I have followed the documentation and multiple tutorials and this should work it seems but no matter what call I make using Tweetinvi to Twitter I get "Forbidden" which when looking at the twitter codes means my authorization is correct but that I am asking for something that I don't have access to, but I am just trying to send a test tweet to see if the program works, which according to Twitter's documentation I should have full access to. Here's the code that I took from Tweetinvi's Tutorial on how to make a "Hello World" tweet but it just doesn't work cuz it returns "Forbidden".

static async Task Main(string[] args)
    {
        var userClient = new TwitterClient("APIKey", "sAPIKey", "AccessToken", "sAccessToken");
        var tweet = await userClient.Tweets.PublishTweetAsync("This is a test tweet");
        Console.WriteLine(tweet);                
    }

It's not just the send tweet function either, if I try to pull any information at all it says it's forbidden so I feel the issue is on Twitter side not my code but I am just trying to learn it as a hobby and have no idea. Just was told Tweetinvi would make everything take 5 minutes and now I am at three days of trying to figure this out. Any help in figuring this out would be nice and greatly appreciated.

  • I have no experience with this api, however this feels like either your authentication info is incorrect, or the twitter side is not set up correctly, options / settings / or what ever you need to do – TheGeneral Nov 18 '21 at 03:09
  • I kinda feel that too, I can verify that the authentication info is correct and that I have setup the project how Tweetinvi says it needs to be setup but just nothing. Authentication error is an "Unauthorized" not "Forbidden". I have granted the app permission to send tweets on the twitter developer site too so I am just at a loss here. Thank you for your advice. – user17443495 Nov 18 '21 at 03:19
  • According to the documentation "Forbidden" is an understood response but without the correct permissions. There should also be a message in the response stating why it returned fobidden. You should be able to check the permissions for the for the access token in the HTTP response header: "All authenticated API requests return an x-access-level header in the HTTP response. The value of the header shows the current permission level of either the Access Token or Bearer Token in use. Possible values are read, read-write, and read-write-directmessages." – Jesper Purup Nov 18 '21 at 04:52
  • I was able to figure it out by going to the forums for the API itself which though the base level of permissions is essential and has the ability to, "Create and delete Tweets on behalf of a user." it does not have the ability to publish said tweets. One step above, Elevated status does. Once becoming elevated the program now works. So long story short, I got confused by the api documentation thinking that "Create and delete Tweets on behalf of a user." the "create" part included publishing but, if anyone else has the error I had. That is the fix. – user17443495 Nov 18 '21 at 05:27
  • @user17443495 might be best to post an answer with a worthy level of detail – TheGeneral Nov 18 '21 at 06:26

1 Answers1

1

Twitter's latest API release [Nov 15th 2021] has an entry level of access called "Essential" that provides access to the v2 API, because this should be the base for most new apps. If you need access to v2 and also to the legacy v1.1 APIs in the same app, you will need "Elevated" access, which is also available for free. The PublishTweetAsync method you are calling in the code in this question is trying to hit the v1.1 Tweet statuses/update endpoint, so your app will need Elevated access in order to make it work.

Andy Piper
  • 11,422
  • 2
  • 26
  • 49
  • Hi, Do you know a Publish method that will use the V2 API ? – Observer Dec 06 '21 at 00:26
  • I do not think Tweetinvi has added support for the new v2 create Tweet method yet. You would need to check with the project maintainer. You can apply for Elevated access for free, and continue to use the v1.1 API to post Tweets (if you do not need the new features like polls etc) – Andy Piper Dec 06 '21 at 14:20