zoukankan      html  css  js  c++  java
  • delphi调用百度API获取token

    procedure TForm1.btn_getTokenClick(Sender: TObject);
    var
      sendData: string;
      url: string;
      ss: TStringStream;
      jsonData: isuperobject;
    begin
      url := 'https://aip.baidubce.com/oauth/2.0/token';
      sendData := 'grant_type=client_credentials&client_id=' + Self.cxTextEdit_clientID.Text + '&client_secret=' + Self.cxTextEdit_clientSecret.Text;
    
      try
        ss := TStringStream.Create('', TEncoding.UTF8);
        ss.WriteString(sendData);
        self.NetHTTPClient1.Accept := 'text/html, application/xhtml+xml, */*';
        self.NetHTTPClient1.ContentType := 'application/x-www-form-urlencoded'; //application/json
        self.NetHTTPClient1.AcceptEncoding := 'UTF-8';
        ss.Position := 0;
    
        jsonData := SO(NetHTTPClient1.Post(url, ss).ContentAsString(tencoding.UTF8));
    
        if Assigned(jsonData['access_token']) then
        begin
          cxMemo1.Clear;
          cxMemo1.Lines.Add(jsonData['access_token'].AsString);
          access_token := jsonData['access_token'].AsString;
        end;
    
      finally
        ss.Free;
      end;
    
    end;
    client_id和client_secret 是你创建百度应用的时候生成的
     
     
  • 相关阅读:
    Mybatis3.2和Spring3.x整合----Myb…
    Mybatis3.2和Spring3.x整合----Myb…
    支持向量分类方法
    KKT了解
    机器学习实战笔记 logistic回归
    朴素贝叶斯进行分类
    决策树算法实现
    KNN算法
    Spring AOP中增强知识
    Java动态代理知识
  • 原文地址:https://www.cnblogs.com/yangxuming/p/15034920.html
Copyright © 2011-2022 走看看