在 Codeigniter 中卷曲 - 错误代码 22,HTTP GET

Curl In Codeigniter - Error Code 22, HTTP GET

我想从名为 BirdEye 的 Third_party API 获取数据。我使用 CURL 的核心 PHP 内置函数来获取数据,它工作正常,现在当我切换到库时我有点困惑,因为它在 return 中没有给我任何响应。

我已经从这里下载了 Curl 库:Curl Library Download and Example

我试图创建一个演示来检查我的库是否正常工作,它成功了。现在,如果我从 Bird-Eye Api 获取数据,我不知道它不会给我任何响应。 我的代码在这里:

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

    public function index()
    {
        $this->load->library('curl');
        $get_url = "https://api.birdeye.com/resources/v1/business/147802929307762?api_key=ApiKeyGoesHere";
        echo $this->curl->simple_get($get_url, false, array(CURLOPT_USERAGENT => true));
        echo $this->curl->error_code;
        $this->load->view('welcome_message');
    }
}

我不知道我哪里出错了我正在将所有必需的参数传递给 Api 并且当我尝试回显错误代码时它给了我 22。我什至搜索了鸟眼文档但什么也没有成立。 Link 到 Api 文档是:Link to BirdEye Api Documentation

所以根据 BirdEye API 你的 cURL 脚本应该像下面这样:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.birdeye.com/resources/v1/business/businessId ");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "Content-Type: application/json",
  "Accept: application/json"
));

$response = curl_exec($ch);
curl_close($ch);

现在,当我将您的库使用代码与上面的示例进行比较时,我发现您缺少几个选项的定义。

在将这些选项添加到您的代码之前,请尝试遵循以下部分:

在示例中,他们没有使用 APIKEY,但是当您使用它时,您可能需要将其作为参数传递,而不是在 get_url 变量中传递。 这意味着:

 $get_url = "https://api.birdeye.com/resources/v1/business/147802929307762";
        echo $this->curl->simple_get($get_url, array('api_key' => 'YourApiKeyGoesHere'), array(..));

如果仍然无效,请尝试将选项添加到您的代码中:

    $this->load->library('curl');
    $get_url = "https://api.birdeye.com/resources/v1/business/147802929307762?api_key=ApiKeyGoesHere";
    echo $this->curl->simple_get($get_url, false, array(CURLOPT_USERAGENT => true, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HEADER => FALSE, CURLOPT_HTTPHEADER => array("Content-Type: application/json", "Accept: application/json")));


    echo $this->curl->error_code;
    $this->load->view('welcome_message');