2017-07-31 64 views
0

我是一名php开发人员,但我对休息和卷曲颇感兴趣。我必须从timekit中检索我的api标记。Timekit curl和php

任何人都可以一步一步地向我解释如何让php脚本执行这里提到的curl命令? http://developers.timekit.io/docs/getting-started

在Google上搜索我找到了Chrome的其他客户端,但它是如何工作的?

感谢和抱歉我的“愚蠢”的问题。

所有最佳

回答

0

这显示了一般的想法。它得到了401响应,但是如果你提供了你的凭证,你应该可以通过cURL与API进行通信。

<?php // demo/temp_mattia.php 
 
/** 
 
* Consume a RESTful API 
 
* 
 
* https://stackoverflow.com/questions/45422567/timekit-curl-and-php 
 
*/ 
 
error_reporting(E_ALL); 
 
echo '<pre>'; 
 

 

 
$url = 'https://api.timekit.io/v2/calendars'; 
 
$user = '[email protected]'; 
 
$pass = 'nvHfRSlhvsnlg4rS7Wt28Ty47qdgegwSu3YK7hPW'; 
 

 
// PREPARE THE CURL CALL 
 
$curl = curl_init(); 
 

 
// SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php 
 
curl_setopt($curl, CURLOPT_URL,   $url ); 
 
curl_setopt($curl, CURLOPT_TIMEOUT,  3 ); 
 
curl_setopt($curl, CURLOPT_HTTPAUTH,  CURLAUTH_ANY); 
 
curl_setopt($curl, CURLOPT_USERPWD,  "$user:$pass"); 
 

 
// GET GOOD ERROR MESSAGES 
 
curl_setopt($curl, CURLOPT_VERBOSE,  TRUE ); 
 
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE ); 
 

 
// IF USING SSL, THIS INFORMATION IS IMPORTANT -- UNDERSTAND THE SECURITY RISK! 
 
curl_setopt($curl, CURLOPT_SSLVERSION,  CURL_SSLVERSION_DEFAULT ); 
 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2 ); // DEFAULT 
 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1 ); // DEFAULT 
 

 
// RUN THE CURL REQUEST AND GET THE RESULTS 
 
$resp = curl_exec($curl); 
 
$errno = curl_errno($curl); 
 
$error = curl_error($curl); 
 
$info = curl_getinfo($curl); 
 
curl_close($curl); 
 

 
// SHOW WHAT CAME BACK 
 
var_dump($resp, $errno, $error, $info);

+0

我已经改变了我的证件,但没有运气。我有这个错误:“字符串(56)”请求的U​​RL返回错误:405方法不允许“”。我所需要的是具有这里描述的api_token http://developers.timekit.io/docs/graphs-reference#section-client-side-authentication –