项目作者: mariohercules

项目描述 :
Fetch data from PWA - Project Online Office 365
高级语言: PHP
项目地址: git://github.com/mariohercules/pwa-project-online.git
创建时间: 2018-01-19T02:21:25Z
项目社区:https://github.com/mariohercules/pwa-project-online

开源协议:

下载


Fetch data from PWA Project Online

  1. <?php
  2. set_time_limit(0);
  3. require_once 'SPOClient.php';
  4. function connectSPO($url,$username,$password)
  5. {
  6. try {
  7. $client = new SPOClient($url);
  8. $client->signIn($username,$password);
  9. return $client;
  10. echo 'You have been authenticated successfully\n';
  11. }
  12. catch (Exception $e) {
  13. echo 'Authentication failed: ', $e->getMessage(), "\n";
  14. }
  15. }
  16. $username = 'USERNAME-OFFICE-365';
  17. $password = 'PASSWORD-OFFICE-365';
  18. $i=0; // register counter
  19. $limit = 300; // limite counter from Project Online (projects)
  20. $skipper = 0; // skipper counter
  21. $topper = $limit; // topper counter
  22. $total_registro = 0;
  23. $ROUTINE = "Projetos";
  24. $start = date('Y-m-d G:i:s');
  25. do {
  26. // Sharepoint PWA Server API
  27. $url = 'https://YOUR-SHAREPOINT-DOMAIN.sharepoint.com/sites/pwa/_api/projectdata/$ROUTINE';
  28. $client = connectSPO($url,$username,$password);
  29. $options = array(
  30. 'list' => '?$format=json&$skip='.$skipper.'&$top='.$topper,
  31. 'id' => NULL,
  32. 'method' => 'GET'
  33. );
  34. $content = $client->getHeaders($options);
  35. $total_registro += sizeof($content->value);
  36. for ($i=0;$i<sizeof($content->value);$i++) {
  37. $data = object_2_array($content->value[$i]);
  38. // Print data from server
  39. var_dump($data);
  40. }
  41. if (sizeof($content->value) == 0) break;
  42. $skipper += $limit;
  43. ++$i;
  44. } while (1);
  45. $end = date('Y-m-d G:i:s');
  46. echo "Starts at $start time";
  47. echo "Ends at $end time";
  48. function object_2_array($result)
  49. {
  50. $array = array();
  51. foreach ($result as $key=>$value)
  52. {
  53. $newKey = toASCII(utf8_decode($key));
  54. if (is_object($value))
  55. {
  56. $array[$newKey]=object_2_array($value);
  57. }
  58. elseif (is_array($value))
  59. {
  60. $array[$newKey]=object_2_array($value);
  61. }
  62. else
  63. {
  64. $array[$newKey]=$value;
  65. }
  66. }
  67. return $array;
  68. }
  69. ?>