1 Reply Latest reply on Dec 2, 2016 10:23 AM by Patrick A Van Der Hyde

    Automatic Login on Tableau Online

    Angélica Flausino

      Hello,
      I am injecting a script in windows forms web browser control, to be able to view the report view without requesting login, could someone help me? My code below. thanks

       

      private void web_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

              {

                  StringBuilder s = new StringBuilder();

                  s.AppendLine("function login(){");

                  s.AppendLine("var request = new XMLHttpRequest();");

                  s.AppendLine("request.open('POST', 'https://online.tableau.com/api/2.4/auth/signin');");

                  s.AppendLine("request.setRequestHeader('Content-Type', 'application/json');");

                  s.AppendLine("request.setRequestHeader('Accept', 'application/json');");

                  s.AppendLine("request.onreadystatechange = function(){");

                  s.AppendLine("if (this.readyState === 4){");

                  s.AppendLine("console.log('Status:', this.status);");

                  s.AppendLine("console.log('Headers:', this.getAllResponseHeaders());");

                  s.AppendLine("console.log('Body:', this.responseText);");

                  s.AppendLine("}");

                  s.AppendLine("};");

                  s.AppendLine("var body = {");

                  s.AppendLine("'tsRequest': {");

                  s.AppendLine("'credentials': {'name' :myusername', 'password': 'mypassword'},");

                  s.AppendLine("'site': { 'contentUrl': 'myurlsite',");

                  s.AppendLine("}");

                  s.AppendLine("};");

                  s.AppendLine("request.send(JSON.stringify(body))}");

                  string script = s.ToString();

       

       

                  HtmlElement head = web.Document.GetElementsByTagName("head")[0];

                  HtmlElement scriptel = web.Document.CreateElement("script");

                  IHTMLScriptElement elem = (IHTMLScriptElement)scriptel.DomElement;

                  elem.text = script;

                  head.AppendChild(scriptel);

                  web.Document.InvokeScript("login");

              }

       

       

              private void ReportView_Load(object sender, EventArgs e)

              {

                  string url = "https://10az.online.tableau.com/t/bi9tableau/views/PFUNC3/Planilha2?:embed=y&:showShareOptions=true&:display_count=no&:showVizHome=no";

                  web.Navigate(url);

              }