TweetInvi and Filtered Streams - c#

Just trying to do some basic testing of the Twitter API.
I've generate my keys/secrets and a bearer token, and been able to do simple Get/Create/Updates fine using the TweetInvi package.
However, I'm just totally stuck at how to get the Filtered Stream working to monitor for at mentions?
I have something like this:
var userClient = new TwitterClient(consumerKey, consumerSecret, accessToken, accessTokenSecret);
var stream = userClient.Streams.CreateFilteredStream();
stream.AddTrack("#AccountToFilterBy");
stream.MatchingTweetReceived += (sender, eventReceived) =>
{
// do some stuff
};
await stream.StartMatchingAnyConditionAsync();
This just won't work for me, I get a 403 error each time. I've tried just passing the consumer key/secret, using the client id key/secret (as I don't really know what it's for) and also added in the Bearer token as well to see if that helps, but just keep getting 403 error each time.
Has anyone got this working, was there a breaking change for TweetInvi as I can't find much info on it?

I am getting the same error, but I do not believe it is related to TweetInvi lib. For example, using Postman Twitter API when you create a tweet, it works. But it gives me same 403 error for for sampled or filtered stream using Postman Twitter API. I think it has to do with twitter permissions.

Related

Issue with Twitter API possibly Tweetinvi (Forbidden)

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.
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.

Why am I getting a 401 unauthorized when using HttpResponseMessage with a secure url?

I have this proprietary code I am working on for my job.
I am writing test cases for it because the code was changed and the test cases are now broken.
It is a C# web Api MVC .Net Framework app
I have a method that I enter a string url in
Then this code executes
HttpResponseMessage response = await Client.GetAsync(url).ConfigureAwait(true);
System.Uri uri = new System.Uri(url); // convert string to Uri
var cert = System.Net.ServicePointManager.FindServicePoint(uri).Certificate;
response.EnsureSuccessStatusCode();
when it gets to response.EnsureSuccessStatusCode() , it gives a 401 unauthorized and then throws an exception not allowing my test to pass
When I try the same thing with http://www.google.com which is not an https, then
it gives a 200. So something is going on with security stuff
What are the things I need to do to get a https to give a 200? Does it need username and password credentials or something or some other token of some sort?
Also, when I test it using Rest Client DHC with the secure https link that was failing above it gives me a 200. However, I had to refresh the bearer token for it to give a 200. If I used an old token it would give a 401.
Furthermoore, when I test a different link like https://www.facebook.com (which is not the one I want to test in my application, just troubleshooting) which is secure, it works giving me a 200 both in my application above and Rest Client DHC even with an old bearer token.
If you're trying to makes CORS requests to web API, you'll need to configure It to accept cross origins requests. If you dont configure your web api to accept cross origin requests, it'll throw these type of errors when calling It. And keep in mind that for web api access, https://www.domain.so and http://www.domain.so are completely diff clients.
Look at this link:
https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api

send tweets using TweetSharp

Currently, I have to post a Tweets (messages ) to the Twitter account. Im using TweetSharp 2.3.1.
Following is my code :
var service = new TwitterService(ConsumerKey, ConsumerSecret);
service.AuthenticateWith(Token, TokenSecret);
TwitterStatus result = service.SendTweet(new SendTweetOptions
{
Status = "Hello, world!"
});
But, Every time Im getting errror: An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll. Though my credentials correct but gettting above error while posting.
Kindly, assist me if anyone knows...
You need to check that you have Read, write, and direct messages access level.
If not then change access level into Read,write and direct message and re-create access token
It seems that TweetSharp is not being maintained anymore. It has lots of issues with Twitter API 1.1 and you may expect several exceptions while using it. I suggest you try to install TweetSharp-Unofficial version insted of Tweetsharp then try to run your application. I faced similar issues with TweetSharp and that solution fixed all my issues.

Getting error :(The remote server returned an error: (401) Unauthorized) when trying to call http://twitter.com/account/verify_credentials.xml

I'm following this Url to authenticate user to my website using twitter login. I'm able to get the access token but when im calling below code
url = "http://twitter.com/account/verify_credentials.json";
xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
im getting 401 unauthorized error. Can anyone guide me what can be the problem
I am not an expert on the Twitter API's but here is a post in the dev.twitter forums that seem to be very similar to what you are experiencing.
https://dev.twitter.com/discussions/1750
Your URL is wrong. It is https://api.twitter.com/1.1/account/verify_credentials.json (or https://api.twitter.com/1/account/verify_credentials.json depending of the version of the Twitter API (1 or 1.1) you use). Twitter recently removed endpoints whose domain name is not api.twitter.com and endpoints without the version of the API : https://dev.twitter.com/discussions/10803
If it is still wrong, ensure that you authorize your requests correctly : https://dev.twitter.com/docs/auth/authorizing-request
NB : Twitter will send you back JSON datas, not XML. You should write "json = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);" instead of "xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);" in your code. If you want XML datas, use this URL : https://api.twitter.com/1/account/verify_credentials.xml. But this last will not work after March 2013.

Tweet An Update Using C# TweetSharp With New OAuth

I don't suppose anyone has used the latest version of TweetSharp to do a twitter status update, I was using the old version and now getting a bit lost with this OAuth stuff and cannot get it to work.
I'd just like some example code of using it to do a simple status update?
This URL will provide the example you need to get your head around OAuth: http://tweetsharp.codeplex.com/wikipage?title=UserGuide&referringTitle=Documentation
From there, there's a method on TwitterService called SendTweet which should be fairly straightforward. Once you have an access token, you can do it like this:
var service = new TwitterService(_consumerKey, _consumerSecret);
service.AuthenticateWith(_accessToken, _accessTokenSecret);
service.SendTweet("I'm totally tweeting!");

Categories