【问题标题】:Box API newbie connection problemsBox API新手连接问题
【发布时间】:2014-01-07 15:35:40
【问题描述】:

我正在尝试连接到 box-api 以读取我的用户在我的文件夹中的文件。我已经创建了文件夹并上传了文件,然后我去 OAuth2 接口获取 API Key。它给了我 api 密钥,所以我将它粘贴到代码中:

 public function indexAction()
{
    try {
        $uri = "https://api.box.com/2.0/folders/0/items?limit=100&offset=0";
        $config = array(
            'adapter'   => 'Zend_Http_Client_Adapter_Curl',
            'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,
                                   CURLOPT_HTTPHEADER=>array("Authorization: Bearer MYKEY"),
                                   CURLOPT_SSL_VERIFYPEER, false,
                                   CURLOPT_USERPWD, "user:password"),
        );
        $client = new Zend_Http_Client($uri, $config);
        $response = $client->request();
        $text= $response->getBody();
    } catch (Zend_Exception $e) {
            echo "Message: " . $e->getMessage() . "\n";
            // Other code to recover from the error
    }
}

关注这个tutorial on youtube

我得到的错误如下:

 Message: Error in cURL request: unable to use client certificate (no key found or wrong pass phrase?) 

我使用名称“test”注册了应用程序。我做错了什么?我错过了什么?

【问题讨论】:

    标签: web-services api registration box-api


    【解决方案1】:

    您可以尝试在不使用 CURLOPT_SSL_VERIFYPEERCURLOPT_USERPWD 选项的情况下传递请求。我认为这些并不是绝对必要的——据我所知,Box 不会进行任何客户端证书验证——它们可能会导致问题。

    【讨论】:

      【解决方案2】:

      使用 Zend http 客户端本身比使用 curl 适配器更好。除了用户名和密码不需要验证。只有在您从 Box-API 的 Oauth2 的授权过程中收到访问令牌后,您才能执行该操作。可以使用的zend http客户端调用如下:

       $client = new Zend_Http_Client('https://api.box.com/2.0/folders/0');
       $client->setMethod(Zend_Http_Client::GET);
       $client->setHeaders('Authorization: Bearer '.$access_token);
       $response = $client->request()->getBody();
      

      我的 2 美分。

      【讨论】:

        猜你喜欢
        • 2015-03-20
        • 2011-01-02
        • 1970-01-01
        • 2014-04-03
        • 1970-01-01
        • 1970-01-01
        • 2014-05-10
        • 1970-01-01
        • 2020-05-30
        相关资源
        最近更新 更多