0

最近 yandex 改变了它的翻译 API 系统。即使验证码正确,我根据新系统创建的连接也会出错。

<?php
    $data = array(
                    "sourceLanguageCode"=>'en',
                    "targetLanguageCode"=>'ru',
                    "texts"=>array('Hello')
    );

        $header = array();
        $header[] = 'Content-Type: Content-Type: application/json';
        $header[] = 'Authorization: Bearer <IAM Token>';

        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, 'https://translate.api.cloud.yandex.net/translate/v2/translate');
        curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, False);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($data));
        $cresponse = curl_exec($ch);
        print_r($cresponse);
?>

在此示例中,我手动输入了 IAMToken。使用 API 创建新的 IAMtoken 时也会出现 404 错误。在 yandex 的文档中,它提供了“https://iam.api.cloud.yandex.net/iam/v1/tokens”端点来获取新的 IAMtoken,但它不起作用。我的代码有什么问题?

4

0 回答 0