Frage

I'm trying to connect to the box-api to read the files of my user in my folder. I've created the folder and uploaded the files, then i went to the OAuth2 interface to obtain an API Key. It has given the api key to me so i pasted it in the code:

 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
    }
}

Following this tutorial on youtube.

The error i'm getting is the following:

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

I registered the application with the name "test". What have I done wrong? What am I missing?

War es hilfreich?

Lösung 2

The use of Zend http client by itself is better than using the curl adapter.Besides the username and password are not required to authenticate. You can perform the operation only after you have received th access token from the authorization procedure of Oauth2 of Box-API. The zend http client call that can be used is the following:

 $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();

My 2 cents.

Andere Tipps

You might try passing the request without the CURLOPT_SSL_VERIFYPEER and CURLOPT_USERPWD options. I don't think those are strictly necessary -- to my knowledge Box doesn't do any client certificate validation -- and they may be causing the problem.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top