Click here to Skip to main content
15,941,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to access my own timeline on Twitter.

On web browswer like google chrome or firefox, this can be accessed on this url:

https://twitter.com/Your Account ID

It is not required to login to just view this page.


I am trying to do the same using Web Client or Http Client in Csharp Winform project.


Somehow, I was able to download the html page from twitter.

However, html page is just an error message saying that "This browser is no longer supported".

I tried to change the agent but it does not really work.

I only need to check what is the latest post in the twitter with simplest code as possible.

Can I achieve this with Web Client or Http Client without using other heavy libary or APi ?

Can someone share some working code ?

What I have tried:

C#
using (WebClient client = new WebClient())
            {

                client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko);)");
                client.DownloadFile(url, "twitter.html");

            }
Posted
Updated 14-Feb-21 7:15am
v2
Comments
auto9817 14-Feb-21 10:44am    
Just getting one raw html file of time line from twitter is more than sufficient, I guess. Hope there is some work around on this.
RickZeeland 14-Feb-21 12:30pm    
Are you using the standard WebBrowser control in your form maybe?
auto9817 14-Feb-21 12:47pm    
Yes, one of the form has webBroswer control. But I do not understand how webBrowser control is related to callinig WebClient or HttpClient.
RickZeeland 14-Feb-21 13:00pm    
In the title you say: "this browser is no longer supported"
auto9817 14-Feb-21 13:06pm    
Yes, that is the exact error showed up on the html file received using WebClient connection. It is strange. I am using WebClient and they recognize me using some sort of Web Broswer, which is not.

1 solution

Try this: Twitter user timeline parsing in c# using dynamic... · GitHub[^]

It could also be a TLS problem, see: httpwebrequest - WebClient request fails because client is seen as outdated browser - Stack Overflow[^]

It could also be that you are using the standard .NET WebBrowser control, which is quite old.
Instead you could try a newer browser control like CefSharp, see: CefSharp - Fast web browser for WinForms and WPF Apps[^]

Or the new Microsoft Edge WebView2 control.
See: Taking the new Chromium WebView2 Control for a Spin in .NET - Part 1 - Rick Strahl's Web Log[^]
 
Share this answer
 
v3
Comments
auto9817 14-Feb-21 13:15pm    
When the form is loaded. This code for TLS is executed too. Apparently, this code is not placed in the same function as the WebClient. I call this code only once in the Form Loading.

ServicePointManager.Expect100Continue = true;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

But still it does not work. I am getting the same error.
RickZeeland 14-Feb-21 13:17pm    
What could also help is upgrading to a newer .NET version 4.5 or higher if you are still using an older version.
auto9817 14-Feb-21 13:18pm    
I use 4.52 .NET Framework at the moment for your information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900