我正在尝试使用PHP和Oauth2使用Zoom的API。我能够使用通用库oauth2-client连接到应用程序并获取令牌。但是,当我尝试提出一个简单的请求时,我收到一条错误消息,说该电子邮件已丢失。这是我的代码:
<?php
session_start();
require __DIR__ . '/vendor/autoload.php';
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => 'meuclientid',
'clientSecret' => 'meuclientsecret',
'redirectUri' => 'http://localhost/teste_oauth2/',
'urlAuthorize' => 'https://zoom.us/oauth/authorize',
'urlAccessToken' => 'https://zoom.us/oauth/token',
'urlResourceOwnerDetails' => 'https://api.zoom.us/v2/users/me'
]);
// If we don't have an authorization code then get one
if (!isset($_GET['code'])) {
$authorizationUrl = $provider->getAuthorizationUrl();
// Get the state generated for you and store it to the session.
$_SESSION['oauth2state'] = $provider->getState();
// Redirect the user to the authorization URL.
header('Location: ' . $authorizationUrl);
exit;
// Check given state against previously stored one to mitigate CSRF attack
}
elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
} else {
try {
// Try to get an access token using the authorization code grant.
$accessToken = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
$request = $provider->getAuthenticatedRequest(
'GET',
'https://api.zoom.us/v2/users/email',
$accessToken,
['email' => '[email protected]']
);
var_dump($provider->getResponse($request));
die('aqui');
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
// Failed to get the access token or user details.
echo $e->getMessage();
exit;
}
}
?>
如您所见,我正在根据请求传递电子邮件。但是我遇到了致命错误:未捕获的GuzzleHttp \ Exception \ ClientException:客户端错误:GET https://api.zoom.us/v2/users/email导致400错误的请求响应:{“ code”:300,“ message”:“需要电子邮件。”}
有人可以帮我吗?
您正在使用
['email' => '[email protected]']
在函数$ provider-> getAuthenticatedRequest中不允许使用的>
您需要使用现有的URL传递它:
$request = $provider->getAuthenticatedRequest( 'GET', 'https://api.zoom.us/v2/users/[email protected]', $accessToken );
我希望这会有所帮助.. !!
Zoom API参考:https://marketplace.zoom.us/docs/api-reference/zoom-api/users/useremail