Delphi百度云服务平台获取token


本文整理自网络,侵删。

 
function Getaccess_token(grant_type,client_id,client_secret:string):string;  //获取token
var
 idhttp2:Tidhttp;
 authHost:string;
 tokSl:Tstringlist;
begin
  authHost:= 'http://aip.baidubce.com/oauth/2.0/token';
  try
    tokSl:=Tstringlist.Create;
    idhttp2:=Tidhttp.Create(nil);
    toksl.Add('grant_type=' + grant_type);
    toksl.Add('client_id=' + client_id);
    toksl.Add('client_secret=' + client_secret);
    Result:=idhttp2.Post(authHost,toksl);
  finally
    toksl.Free;
    idhttp2.DisposeOf;
  end;
end;

可得到如下结果


{
    "access_token": "1.a6b7dbd428f731035f771b8d********.86400.1292922000-2346678-124328",
    "expires_in": 2592000,
    "refresh_token": "2.385d55f8615fdfd9edb7c4b********.604800.1293440400-2346678-124328",
    "scope": "public audio_tts_post ...",
    "session_key": "ANXxSNjwQDugf8615Onqeik********CdlLxn",
    "session_secret": "248APxvxjCZ0VEC********aK4oZExMB",
}

scope中含有audio_tts_post 表示有语音合成能力,没有该audio_tts_post 的token调用接口会返回502错误。 在结果中可以看见 token = 1.a6b7dbd428f731035f771b8d********.86400.1292922000-2346678-124328,在2592000秒(30天)后过期。
响应数据包如下所示,其中 “access_token” 字段即为请求 REST API 所需的令牌, 默认情况下,Access Token 有效期为30天,开发者需要对 Access Token的有效性进行判断,如果Access Token过期可以重新获取。

相关阅读 >>

Delphi 在窗体上创建自己的光标并输入文字

Delphi中inputbox 和inputquery 函数的使用

Delphi 木马配置器通用写法(末尾追加数据的方法)

Delphi getwebbrowserhtml 获取网页源代码

Delphi win7,win2008,win2003,winxp 屏蔽ctrl+alt+del

Delphi 获取临时文件夹路径

Delphi 正则表达式校验手机号

Delphi xe firemonkey的stylebook皮肤控件的使用

Delphi获取进程占用内存

Delphi is1251char

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...