Guzzle with telegram Bot API - 'GetMe' 方法不显示用户对象
Guzzle with telegram Bot API - 'GetMe' method not displaying a user object
我有密码
public function getClient(){
$token = getenv('TELEGRAM_TOKEN');
$uri = 'https://api.telegram.org/bot'.$token.'/';
$client = new Client(['base_url' => $uri]);
return $client;
}
public function getMyBot(){
$client = $this->getClient();
$response = $client->get( '/getMe' );
dd($response);
}
但是我没有像 docs 中那样返回用户对象,而是显示了一个 'response' 对象。
Response {#188 ▼
-reasonPhrase: "OK"
-statusCode: 200
-effectiveUrl: "https://core.telegram.org/bots"
-headers: array:9 [▼
"server" => array:1 [▶]
"date" => array:1 [▶]
"content-type" => array:1 [▶]
"content-length" => array:1 [▶]
"connection" => array:1 [▶]
"pragma" => array:1 [▶]
"cache-control" => array:1 [▶]
"x-frame-options" => array:1 [▶]
"strict-transport-security" => array:1 [▶]
]
-headerNames: array:9 [▼
"server" => "Server"
"date" => "Date"
"content-type" => "Content-Type"
"content-length" => "Content-Length"
"connection" => "Connection"
"pragma" => "Pragma"
"cache-control" => "Cache-control"
"x-frame-options" => "X-Frame-Options"
"strict-transport-security" => "Strict-Transport-Security"
]
-body: Stream {#189 ▼
-stream: :stream {@280 ▶}
-size: null
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
-customMetadata: []
}
-protocolVersion: "1.1"
}
无论如何获取用户对象?我正在使用 php 5.4 和 Guzzle 5.3,以及 laravel 5.0.
编辑:我尝试使用 getBody() 方法以及 getBody->getContents() 方法,但它不起作用,getBody 只会显示响应的流部分,getContents 会给出一个奇怪的 HTML 文件.
JSON_DECODE 也不起作用,它 returns 错误代码 4 即 JSON_ERROR_SYNTAX。响应应该是 JSON 形式吗?
您需要显示正文的内容。
dd($response->getBody()->getContents())
顺便说一下,您可以使用 unofficial laravel reqady SDK,它也适用于 Guzzle。
我有密码
public function getClient(){
$token = getenv('TELEGRAM_TOKEN');
$uri = 'https://api.telegram.org/bot'.$token.'/';
$client = new Client(['base_url' => $uri]);
return $client;
}
public function getMyBot(){
$client = $this->getClient();
$response = $client->get( '/getMe' );
dd($response);
}
但是我没有像 docs 中那样返回用户对象,而是显示了一个 'response' 对象。
Response {#188 ▼
-reasonPhrase: "OK"
-statusCode: 200
-effectiveUrl: "https://core.telegram.org/bots"
-headers: array:9 [▼
"server" => array:1 [▶]
"date" => array:1 [▶]
"content-type" => array:1 [▶]
"content-length" => array:1 [▶]
"connection" => array:1 [▶]
"pragma" => array:1 [▶]
"cache-control" => array:1 [▶]
"x-frame-options" => array:1 [▶]
"strict-transport-security" => array:1 [▶]
]
-headerNames: array:9 [▼
"server" => "Server"
"date" => "Date"
"content-type" => "Content-Type"
"content-length" => "Content-Length"
"connection" => "Connection"
"pragma" => "Pragma"
"cache-control" => "Cache-control"
"x-frame-options" => "X-Frame-Options"
"strict-transport-security" => "Strict-Transport-Security"
]
-body: Stream {#189 ▼
-stream: :stream {@280 ▶}
-size: null
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
-customMetadata: []
}
-protocolVersion: "1.1"
}
无论如何获取用户对象?我正在使用 php 5.4 和 Guzzle 5.3,以及 laravel 5.0.
编辑:我尝试使用 getBody() 方法以及 getBody->getContents() 方法,但它不起作用,getBody 只会显示响应的流部分,getContents 会给出一个奇怪的 HTML 文件.
JSON_DECODE 也不起作用,它 returns 错误代码 4 即 JSON_ERROR_SYNTAX。响应应该是 JSON 形式吗?
您需要显示正文的内容。
dd($response->getBody()->getContents())
顺便说一下,您可以使用 unofficial laravel reqady SDK,它也适用于 Guzzle。