Log in after redirect twitch/tv

hi
i want to redirect twitch/tv homepage after log in
here is my code

(i already fill the ID and client_id)
when i click the button, local page show the JSON response about my id, display name, etc…
i want to redirect twitch/tv homepage as signed in
how could i do??

Where is your code?

You are following the oAuth authentication flow as described here -> https://dev.twitch.tv/docs/authentication#oauth-authorization-code-flow-user-access-tokens

my code like this
package jsoup;

import java.io.IOException;

import org.openqa.selenium.chrome.ChromeDriver;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class twitch {
private static WebDriver driver;

public static void main(String[] args) throws InterruptedException, IOException {

	// Open the Browser
	System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");

	Thread.sleep(1000);
	driver = new ChromeDriver();

	Thread.sleep(1000);

	String URL = "https://api.twitch.tv/kraken/oauth2/authorize?response_type=token+id_token&client_id=(fill my client id)&redirect_uri=(fill my rediretion url)&scope=viewing_activity_read+openid";

	driver.get(URL);
}

}

but when i execute the program, it doesn’t log in
(i used webdriver)

I don’t know webdriver. But sounds like you are doing it wrong/expecting something else to happen. Does webdriver just display the page in order for the user to login?

under oAuth you are supposed to direct a user to the authorize url, where a User then logins and grants your client access to their account, that then GET’s back to your return url which then does the oAuth code dance to exchange for a token.

@BarryCarlyon it’s part of selenium, which is a web browser automation library.

@_Kim the user needs to actually open the first authorization URL in their browser, login if they haven’t yet, and authorize the application. Selenium is not what you need here. If it’s a desktop application you’re creating, you’ll want to open the URL using the user’s default browser. If it’s a web server backend application, you’ll want to redirect the user to that URL.

i try like this

package jsoup;

import java.awt.Desktop;
import java.net.URI;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class login_test {
public static void main(String args[]) throws Exception {

	// Create Desktop object
	Desktop d = Desktop.getDesktop();

	// Browse a URL, say google.com
	d.browse(new URI("https://google.com/"));
	d.browse(new URI("http://twitch.tv/"));
			
	Document doc = Jsoup.connect(URL).get() <--it's not work
	System.out.println(doc);
}

}

l don’t know exactly but it automatically signed in the page(http://twitch.tv/)
In this moment, i have another question
after signed in the page how to i get the page source??
i want it to get some page source(like HTML code for page)<=

Why are you after the page source?

It sounds like you are trying to do something that you are not supposed to be doing?

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.