HttpWebRequest to login youtube

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buynsell
    New Member
    • Jan 2012
    • 5

    HttpWebRequest to login youtube

    After bunch of searching on google I end up with posting new thread for help,

    I am trying to login to youtube using webRequest/Response but no success, it is returning source code which tells that "Your browser cookies disabled ..." etc.

    Attaching my code and can someone tell me the solution or if any better way to do this ?

    I know that youtube api offer these function but I've to do without api for my project.

    here is my source code

    Code:
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    CookieContainer container = new CookieContainer();
                    request.CookieContainer = container;
    
                    StreamReader reader;
                    Stream stream;
    
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
                        stream = response.GetResponseStream();
                        reader = new StreamReader(stream);
    
                        string temp1 = reader.ReadToEnd();
                        richTextBox1.Text = temp1;
                        
                        String Pattern = "name=\"GALX\"[\\s]*value=\"([a-zA-Z0-9-_\\.]*)\"";
                        galx = richTextBox1.Text;
                        Match myMatch = Regex.Match(galx, Pattern);
                        galx = myMatch.Groups[1].ToString();
    
                        string url2 = "https://www.google.com/accounts/ServiceLoginAuth?service=youtube&ltmpl=sso&continu e=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_h andle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_U S%26next%3D%252F&service=youtube&uilel=3&ltmpl=sso &hl=en_US&ltmpl=sso&GALX=" + galx + "&Email=username&Passwd=password&rm Shown=1&signIn=Sign+in&asts=";
    
                        richTextBox1.Text = "";
    
                        HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(url2);
                        request2.CookieContainer = container;
                        request2.Method = "POST";
                        request2.Referer = "https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true& continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Fa ction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl %3Den_US%26next%3D%252F&hl=en_US&ltmpl=sso";
                        request2.MaximumAutomaticRedirections = 50;                    
                        request2.AllowAutoRedirect = true;
                        request2.KeepAlive = true;
                        request2.ContentLength = 0;
                        container = request2.CookieContainer;
    
                        HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
                        response2.Cookies = request2.CookieContainer.GetCookies(request2.RequestUri);
    
    
                        Stream responseStream = response2.GetResponseStream();
                        response2.Cookies = request2.CookieContainer.GetCookies(request2.RequestUri);
                        request2.CookieContainer = container;
    
                        StreamReader ressponseReader = new StreamReader(response2.GetResponseStream());
    
                        string temp;
                        temp = ressponseReader.ReadToEnd().ToString();
                        richTextBox2.Text += temp;
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    When returned code says your browser dont support cookie it means, you are not sending cookie back to the server.

    in fact when server get a log in request it also look for previously set cookie. so make sure you are sending back those cookie that is send by google. And one thing, there is no special log in for youtube all google use the same login info.

    Comment

    • buynsell
      New Member
      • Jan 2012
      • 5

      #3
      hey thnx for the reply,

      I guess I am sending back cookies already here,
      Code:
      request2.CookieContainer = container;
      can you please be more specific how to send cookie back if not like this, I am not very good at this httpwebrequest/response,

      I already tried alot googling but still no success !!!
      Stuck badly

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        did you check whether container is empty or what?

        Comment

        • buynsell
          New Member
          • Jan 2012
          • 5

          #5
          no container isn't empty, when I checked its count that is 5.

          Comment

          • webmarketing
            New Member
            • Jan 2012
            • 1

            #6
            I think other site proprietors should take blog.blackhc.ne t as an model, very clean and excellent user friendly style and design, let alone the content. You are an expert in this topic!

            Comment

            Working...