Q
Q
Qixing2015-01-12 09:33:04
PHP
Qixing, 2015-01-12 09:33:04

How to debug Yandex Original Texts API?

Good afternoon. Until December 31, the original api texts worked fine. https://tech.yandex.ru/webmaster/doc/dg/reference/...
Since January 1, he does not want to. Updated the token, updated the key. Authorization is successful (if the left token - then immediately an error)
Issues http code 100 and the server response is false. I tried everything.
Some code snippets

public $appId;
    public $appSecret;
    public $yandexToken;
    public $siteId;
    protected  $host = 'webmaster.yandex.ru';
    protected  $url;
    protected $timeOut = 30;

    public function init()
    {
        $this->url = "/api/v2/hosts/" . $this->siteId . "/original-texts/";
        parent::init();
    }


    private function getPage($curlOptions = array())
    {
        $ch = curl_init();
        curl_setopt_array($ch, $curlOptions);
        $result = curl_exec($ch);
        $info = curl_getinfo($ch);
       
        return array('result' => $result, 'info' => $info);
    }

    # Функция непосредсвенной подготовки на выполнения запроса добавления уникального текста
    private function performYandexWebmasterApiRequest(
        $url,
        $requestType = 'POST',
        $curlOptions = array(),
        $additionalHeaders = array()
    ) {
        $headers = array(
            "{$requestType} {$url} HTTP/1.1",
            'Host: webmaster.yandex.ru',
            'Authorization: OAuth ' . $this->yandexToken
        );

        $headers = array_merge($headers, $additionalHeaders);
        $requestOptions = array(
            CURLOPT_URL => $this->host . $this->url,
            CURLOPT_SSL_VERIFYPEER => 0,
            CURLOPT_CONNECTTIMEOUT => $this->timeOut,
            CURLOPT_HTTPHEADER => $headers,
            CURLOPT_RETURNTRANSFER => 1
        );
        if (count($curlOptions)) {
            foreach ($curlOptions as $curlOption => $curlOptionValue) {
                $requestOptions[$curlOption] = $curlOptionValue;
            }
        }

        $response = $this->getPage($requestOptions);

        return $response;
    }

    public function add($text)
    {
        $text = strip_tags(html_entity_decode($text));
        $text = urlencode("<original-text><content>{$text}</content></original-text>");
        $additionalHeaders = array('Content-Length: ' . mb_strlen($text));
        $curlOptions = array(CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_POSTFIELDS => $text);
        $response = $this->performYandexWebmasterApiRequest($this->url, 'POST', $curlOptions, $additionalHeaders);




        if($response['info']['http_code'] == 201)
        {
            $xml = new SimpleXMLElement($response['result']);
            return $xml->id;
        }
        else
            return false;



    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rencom, 2015-01-12
@Rencom

1v1 problem, texts stopped sending on December 31st

M
Max, 2015-01-12
@AloneCoder

Everyone has such a problem, judging by the answer of the support, they have a problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question