Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 2.85 KB

0-Examples-EN.md

File metadata and controls

71 lines (52 loc) · 2.85 KB

← Home | Examples(中文) | Client & Credentials →


Requirements

  • To use Alibaba Cloud SDK for Java, you must have an Alibaba Cloud account as well as an AccessKey ID and an AccessKey Secret. Create and view your AccessKey on the RAM console or contact your system administrator.
  • To use the Alibaba Cloud SDK for Java to access the APIs of a product, you must first activate the product on the Alibaba Cloud console if required.
  • The Alibaba Cloud Java SDK requires JDK 1.6 or later.

Installation

If you use Apache Maven to manage Java projects, you only need to add corresponding dependencies to the pom.xml files of the projects. To use the OCR SDK as an example, you only need to declare the following the dependencie in the pom.xml file.

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>ocr20191230</artifactId>
    <version>[0.0.1,1.0.0)</version>
</dependency>

Quick Examples

The following code example shows the three main steps to use Alibaba Cloud SDK for Java :

  1. Create and initialize a Client instance.

  2. Create and set up parameters RuntimeObject instance.

  3. Create an API request and set parameters.

  4. Initiate the request and handle the response or exceptions.

import com.aliyun.ocr20191230.Client;
import com.aliyun.ocr20191230.models.RecognizeBankCardAdvanceRequest;
import com.aliyun.ocr20191230.models.RecognizeBankCardResponse;
import com.aliyun.tearpc.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

import java.io.FileInputStream;
import java.io.InputStream;

public class TeaDemo {

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

        // 1 Create and initialize a Config instance.
        Config authConfig = new Config();
        authConfig.accessKeyId = "your accessKeyId";
        authConfig.accessKeySecret = "your accessKeySecret";
        authConfig.type = "access_key";
        authConfig.endpoint = "your endpoint";
        authConfig.regionId = "cn-beijing";

        Client authClient = new Client(authConfig);

        // 2 Create and set up parameters RuntimeObject instance.
        RuntimeOptions runtime = new RuntimeOptions();

        // 3 Create an API request and set parameters.
        RecognizeBankCardAdvanceRequest request = new RecognizeBankCardAdvanceRequest();
        InputStream inputStream = new FileInputStream("your file");
        request.imageURLObject = inputStream;

        // 4 Initiate the request and handle the response or exceptions.
        RecognizeBankCardResponse authResponse = authClient.recognizeBankCardAdvance(request, runtime);
    }
}

← Home | Examples(中文) | Client & Credentials →