Im new to php。我有以下情況:訪問數組中的一個元素
$params = array("code" => $_GET["code"], "redirect_uri" => $redirectUrl);
$response = $client->getAccessToken($accessTokenUrl, "authorization_code", $params);
$accessTokenResult = $response["result"];
$client->setAccessToken($accessTokenResult["access_token"]);
$client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_BEARER);
$response = $client->fetch("https://oauth.reddit.com/api/v1/me.json");
而結果(print_r
)從$response
這是一個:
Array (
[result] => Array
(
[name] => histograf
[created] => 12869553489
[gold_creddits] => 0
[created_utc] => 12869553489
[link_karma] => 1
[comment_karma] => 11
[over_18] => 1
[is_gold] =>
[is_mod] => 0
[has_verified_email] =>
[id] => ap11l
)
[code] => 200
[content_type] => application/json; charset=UTF-8)
的一點是,現在,我怎麼能訪問該元素的名稱?我需要讓用戶名在pgm中更進一步。
我已經試過這些,沒有工作:
$username = $response[0];
$username = $response->name;
$username = $response[0]name;
非常感謝你!現在工作! – histograf