Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:57:47+00:00 2026-06-12T16:57:47+00:00

I’m fairly new to using WebRequests in C# and would like some help logging

  • 0

I’m fairly new to using WebRequests in C# and would like some help logging into YouTube and storing cookies into a cookie container. Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:57:48+00:00Added an answer on June 12, 2026 at 4:57 pm

    If you are using the .NET client library (http://code.google.com/p/google-gdata/) then it will take care of authenticating for you when needed using the credentials you provided:

    https://developers.google.com/youtube/2.0/developers_guide_dotnet#Authentication

    GData in C#

    When using the GData API there’s no explicit logout method, you can invalidate your token but it will also expire after some time if you don’t use it. Specific details on how to invalidate the token differ according to the authentication mechanism adopted (OAuth, AuthSub, ClientLogin).

    You can also refer to this article on CodeProject, Manage YouTube using C# and Youtube API 1.6

    YouTubeService service = new YouTubeService();
    service.setUserCredentials(txtUser.Text , txtPassword.Text);
    try { service.QueryClientLoginToken(); }
    catch(System.Net.WebException e) { MessageBox.Show(e.Message); }
    

    ADDED: I have tweaked below code to match your requirement.

    class YouTube
    {
        public void Login()
        {
            HttpWebRequest request = GetNewRequest("https://accounts.google.com/ServiceLoginAuth", cookies);
            request.Referer = "https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26feature%3Dsign_in_button%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252F&uilel=3&hl=en_US&service=youtube";
            request.Host = "accounts.google.com";
            Dictionary<string, string> parameters = new Dictionary<string, string>{
                {"continue","https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26feature%3Dsign_in_button%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252F"},
                {"service","youtube"},{"uilel","3"},{"dsh","157212168103955870"},{"hl","en_US"},
                {"GALX","PTqcwpZb2aE"},{"pstMsg","1"},{"dnConn",""}, {"checkConnection","youtube%3A248%3A1"}, 
                {"checkedDomains","youtube"}, {"timeStmp",""}, {"secTok",""}, {"Email","username"}, {"Passwd","password"}, 
                {"signIn","Sign+in"}, {"PersistentCookie","yes"}, {"rmShown","1"}};
            HttpWebResponse response = MakeRequest(request, cookies, parameters);
            response.Close();
        }
    
        private static CookieContainer cookies = new CookieContainer();
    
        private static HttpWebRequest GetNewRequest(string targetUrl, CookieContainer SessionCookieContainer)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUrl);
            request.CookieContainer = SessionCookieContainer;
            request.AllowAutoRedirect = false;
            return request;
        }
    
        private static HttpWebResponse MakeRequest(HttpWebRequest request, CookieContainer SessionCookieContainer, Dictionary<string, string> parameters = null)
        {
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5Accept: */*";
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            request.CookieContainer = SessionCookieContainer;
            request.AllowAutoRedirect = false;
    
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            string postData = string.Empty;
            foreach (KeyValuePair<String, String> parametro in parameters)
            {
                if (postData.Length == 0)                
                    postData += String.Format("{0}={1}", parametro.Key, parametro.Value);                
                else                
                    postData += String.Format("&{0}={1}", parametro.Key, parametro.Value);                
            }
    
            byte[] postBuffer = UTF8Encoding.UTF8.GetBytes(postData);
            using (Stream postStream = request.GetRequestStream())
            {
                postStream.Write(postBuffer, 0, postBuffer.Length);
            }
    
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            SessionCookieContainer.Add(response.Cookies);
    
            while (response.StatusCode == HttpStatusCode.Found)
            {
                response.Close();
                request = GetNewRequest(response.Headers["Location"], SessionCookieContainer);
                response = (HttpWebResponse)request.GetResponse();
                SessionCookieContainer.Add(response.Cookies);
            }
            return response;
        }
    }
    

    Reference: http://social.msdn.microsoft.com/Forums/pl-PL/ncl/thread/40d249b5-a9ad-4068-8853-629fb20584a0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like to count the length of a string with PHP. The string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.