0

我正在尝试使用 PHP 和 Oauth2 使用 Zoom 的 API。我能够使用通用 lib 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' => 'meuemail@gmail.com']
        );


        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 Bad Request response: {"code":300," message":"电子邮件是必需的。"}

谁能帮我?

4

1 回答 1

0

您正在使用

['email' => 'meuemail@gmail.com']

这在$provider->getAuthenticatedRequest函数中是不允许的

您需要使用现有 URL 传递它:

        $request = $provider->getAuthenticatedRequest(
            'GET',
            'https://api.zoom.us/v2/users/email?email=meuemail@gmail.com',
            $accessToken
        );

我希望这有帮助..!!

缩放 API 参考:https ://marketplace.zoom.us/docs/api-reference/zoom-api/users/useremail

OAuth 参考:https ://github.com/thephpleague/oauth2-client

于 2020-05-15T20:08:21.000 回答