市场 API 是否在每个帐户的基础上阻止卷曲


Does Marketo API block curl on a per account basis?

我正在尝试使用 curl 连接到 Marketo.com REST API。我无法从标识服务获得响应。我只收到错误消息

"[curl] 6:无法解析主机'MY_CLIENT_ENDPOINT.mktorest.com

,但我可以打印构造的 url 并将其粘贴到浏览器地址栏中,这将提供带有 access_token 元素的预期响应。

我可以在 php 和终端中使用 curl 来访问我的 gmail 帐户,以便 curl 能够访问 https 服务。我尝试将 curl url 中的参数作为 get 请求发送,并使用 curl 的 -F 选项作为 post 请求声明它们

我的应用程序使用 github 上可用的 dchesterton/marketo-rest-api,但我也尝试了一个简单的 php curl 请求来获取访问令牌。

private function getToken() {
    $url = "$this->client_url/identity/oauth/token?grant_type=client_credentials&client_id=$this->client_id&client_secret=$this->client_secret";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($ch);
    $errors = curl_error($ch);
    curl_close($ch);
    file_put_contents($this->logDir . 'access_token_response' . date('Y-m-d') . '.txt', $url . "'n" . $response . "'n", FILE_APPEND);
    if ($errors) {
        file_put_contents($this->logDir . 'access_token_errors' . date('Y-m-d') . '.txt', $errors . "'n", FILE_APPEND);
    }
    return $response['access_token'];
}

同样,这失败并出现相同的错误,但会产生一个格式完美的 url,我可以将其粘贴到浏览器中并获得有效的响应。我也尝试过使用 post 而不是像我提到的所有其他测试那样获得,并且这些已经在我的本地主机和测试服务器上尝试过。

谁能向我解释为什么这会失败?市场是否基于每个帐户阻止卷曲?

我试图实现类似的东西,但我的代码不起作用。我不确定到底是什么失败了,但我尝试了您的代码,经过一些轻微的修改后,它似乎可以完美运行:

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($request_data));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($curl);
$errors = curl_error($curl);
curl_close($curl);

我希望这有所帮助。