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 是你创建百度应用的时候生成的
原文地址:https://blog.csdn.net/tjsoft/article/details/143697980
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!