Help Center> Image Recognition> SDK Reference> Using Java SDK> SDK Project Using Token Authentication

SDK Project Using Token Authentication

Two authentication methods, token authentication and AK/SK authentication, are available. This section uses token authentication as an example.

(You can use Image Tagging after performing the following operations. You only need to change the username and password instead of compiling code.)

  1. Open the TokenDemo.java file in the com.huawei.ais.demo package, and change the values of username and password in the main function to the actual username and password registered with the system. The sample code is as follows:

    /**
     * Invoke the main entrypoint function.
     */
    public static void main(String[] args) throws URISyntaxException, UnsupportedOperationException, IOException {
        String username = "zhangshan";   // Enter the username.
        String password = "*******";     // Enter the corresponding password.
    
        String token = getToken(username, password, projectName);
        System.out.println(token);
        requestImageTaggingBase64(token, "data/image-tagging-demo-1.jpg");
        }

  2. After modification, run the TokenDemo.java file. On the console, you can see the recognition result using token authentication.