In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Java Baidu handwritten character recognition interface configuration code, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
The code is as follows:
Package org.fh.util;import org.json.JSONObject;import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import java.util.List;import java.util.Map / * Note: get text recognition token class * author: FH Admin * from:fhadmin.cn * / public class AuthTextService {/ * obtain permission token * @ return return example: * {* "access_token": "xxxxxxx" * "expires_in": 2592000 *} * / public static String getAuth () {/ / the API Key obtained on the official website is updated to your registered String clientId = "xxxxxxxx" / / the Secret Key obtained on the official website is updated to your registered String clientSecret = "xxxxxxxxxxx"; return getAuth (clientId, clientSecret);} / * * obtain API access token * the token has a certain validity period and needs to be managed by itself, and it needs to be re-obtained when it expires. * @ param ak-API Key obtained from Baidu Cloud official website * @ param sk-example of Securet Key * @ return assess_token obtained from Baidu Cloud official website: * "24.460da4889caad24cccdb1fea17xxxxx" * / public static String getAuth (String ak, String sk) {/ / obtain token address String authHost = "https://aip.baidubce.com/oauth/2.0/token?";" String getAccessTokenUrl = authHost / / 1. Grant_type is a fixed parameter + "grant_type=client_credentials" / / 2. API Key + "& client_id=" + ak / / 3 obtained from the official website. Secret Key + "& client_secret=" + sk; try {URL realUrl = new URL (getAccessTokenUrl); / / Open connection to URL HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection (); connection.setRequestMethod ("GET"); connection.connect () / / get all response header fields Map map = connection.getHeaderFields (); / / iterate through all response header fields for (String key: map.keySet ()) {System.err.println (key + "-->" + map.get (key) } / / define the BufferedReader input stream to read the URL response BufferedReader in = new BufferedReader (new InputStreamReader (connection.getInputStream (); String result = ""; String line; while ((line = in.readLine ())! = null) {result + = line } / * return result example * / System.err.println ("result:" + result); JSONObject jsonObject = new JSONObject (result); String access_token = jsonObject.getString ("access_token"); return access_token } catch (Exception e) {System.err.printf ("failed to get token!") ; e.printStackTrace (System.err);} return null;}} after reading the above, have you mastered the method of how to write the code for the configuration of the java Baidu handwritten character recognition interface? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.