-1

我一直致力于为学生提供在线教育的 Laravel 项目。我想使用视频会议的 Zoom 服务,以便老师可以通过视频会议与学生联系。按照 API 参考文档,我在 Zoom 上注册了一个应用程序。我按照文档获得了 API 密钥和 API 机密以及访问令牌。

我正在发送后续请求以从 Zoom 发布/获取数据,但我收到了如下错误消息:

Client error: `POST https://api.zoom.us/v2/accounts` resulted in a `400 Bad Request` response: {"code":200,"message":"Invalid api key or secret."}  

我在标头中发送 API 密钥和 API 机密,但仍然收到相同的错误。可能我在请求过程中做错了什么,或者可能是别的什么,我不知道。我在互联网上搜索了如何将 Zoom 与 Laravel 应用程序集成,但找不到任何有用的信息。

谁能帮我弄清楚我做错了什么?有人可以提供一些有关 Zoom API 与 Laravel 集成的有用资源吗?

class AccountsController extends Controller
{
    public function createAccount(Request $request) {

        $client_id = env('CLIENT_ID');
        $client_secret = env('CLIENT_SECRET');

        $content = "grant_type=client_credentials&client_id=$client_id&client_secret=$client_secret";
        $token_url="https://zoom.us/oauth/token";

        $curl = curl_init();

        curl_setopt_array($curl, array(

            CURLOPT_URL => $token_url,
            CURLOPT_SSL_VERIFYPEER => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $content
        ));

        $data = curl_exec($curl);
        curl_close($curl);
        $result = json_decode($data);

        $access_token = $result->access_token;
        $client = new \GuzzleHttp\Client();

        $api_key = env('API_KEY');
        $api_secret = env('API_SECRET');

        $response = $client->request('POST', 'https://api.zoom.us/v2/accounts', [
            'headers' => [
                'apikey' => $api_key,
                'apisecret' => $api_secret,
                'Accept' => 'application/json',
                'Content-Type' => 'application/json',
                'Authorization'     => 'Bearer '. $access_token
            ],
            'form_params' => [
                'first_name' => $request->first_name,
                'last_name' => $request->last_name,
                'email' => $request->email,
                'password' => $request->password,
            ],
        ]);
        $response = $response->getBody()->getContents();
        dd($response);
    }
}

这是针对此 API 调用的 json 响应:

{
  "id": "string",
  "owner_id": "string",
  "owner_email": "string",
  "created_at": "string"
}
4

1 回答 1

0

我注意到您正在尝试使用:grant_type=client_credentials来获取access_token. grant_type=client_credentials仅用于获取Chatbot令牌

通过 OAuth 应用类型调用 Zoom API,您必须使用:grant_type=code来获取access_token.

或者

对于服务器到服务器的集成,您可以使用JWT 应用程序类型来调用 Zoom API。

有关Zoom 应用类型的更多详细信息,请点击此处。

(提问者移至 Zoom 开发者论坛:https ://devforum.zoom.us/t/invalid-api-key-or-secret-error )

于 2019-07-30T21:17:31.923 回答