(PHP)如何将特定信息从API转换为变量?

毛绒玩具:

我有一些来自API的输出:

{"id":"usr_3290ad77-a2d8-40da-9edf-21e624c23f27","username":"knuffelbeestje","displayName":"KnuffelBeestje","bio":"Working on a new worldǃ\nDC Hub is coming soon to community labsǃ","bioLinks":["https://steamcommunity.com/id/KnuffelBeestje","https://twitch.tv/knuffeldiertje"],"currentAvatarImageUrl":"https://api.vrchat.cloud/api/1/file/file_d66e4e65-6ce7-4321-8770-1c70840adfa9/1/file","currentAvatarThumbnailImageUrl":"https://api.vrchat.cloud/api/1/image/file_d66e4e65-6ce7-4321-8770-1c70840adfa9/1/256","tags":["show_social_rank","system_trust_basic","system_avatar_access","system_world_access","language_nld","language_eng"],"developerType":"none","last_login":"","last_platform":"standalonewindows","allowAvatarCopying":false,"isFriend":false,"friendKey":"","location":"","worldId":"offline","instanceId":"offline"}int(1) 1

我怎么知道的:

$curl = curl_init('https://api.vrchat.cloud/api/1/users/KnuffelBeestje/name? 
apiKey=JlE5Jldo5Jibnk5O5hTx6XVqsJu4WJ26');
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Authorization: Basic PrivateKey']);
$apicontent = curl_exec($curl);
curl_close($curl);

var_dump(json_decode($apicontent, true));

(API密钥是公共的,不用担心)。我想将“ bio”保存到php中的变量中,该怎么办?谢谢。

乔尔·海梅(Joel Jaime):

您需要的是这样的东西

$curl = curl_init('https://api.vrchat.cloud/api/1/users/KnuffelBeestje/name?apiKey=JlE5Jldo5Jibnk5O5hTx6XVqsJu4WJ26');
curl_setopt($curl, CURLOPT_HTTPHEADER,[
    'Authorization: Basic PrivateKey'
]);
$apicontent = curl_exec($curl);
curl_close($curl);

$content = json_decode($apicontent, true);
$id = $content['id'];
$username = $content['username'];
$bio = $content['bio'];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章