2011-05-24 4 views
5

तो मैं इस GitHub लिंक से एक आवरण वर्ग डाउनलोड किया मदद की जरूरत है:क्या किसी ने इस हाइराइज एपीआई PHP रैपर लाइब्रेरी के साथ काम किया है? मैं के सत्यापन

https://github.com/ignaciovazquez/Highrise-PHP-Api

और मैं बस किसी भी प्रतिक्रिया जो भी पाने के लिए कोशिश कर रहा हूँ। अब तक, मैं अपने प्रमाण-पत्रों के साथ प्रमाणित भी नहीं कर सकता, इसलिए मैं सोच रहा था कि अगर कोई भी एपीआई इस्तेमाल करता है तो मेरी मदद कर सकता है।

मेरे पास कोई तर्क के साथ टर्मिनल पर परीक्षण फ़ाइलों में से एक चल रहा है की कोशिश की और यह है कि क्या यह मुझे बताया है:

Usage: php users.test.php [account-name] [access-token] 

ठीक है, तो फिर अपनी उपलब्धियों को प्राप्त करने के लिए फैसला किया। तो मैं यही समझता हूं, और, कृपया सही है कि मैं गलत हूं:

खाता-नाम वह हिस्सा है जो आपके उच्च खाते में यूआरएल में जाता है। इसलिए यदि आपके यूआरएल है:

https://exampleaccount.highrisehq.com/

फिर अपना खाता नाम है: "exampleaccount"

और अपने पहुँच टोकन अपने प्रमाणीकरण टोकन है कि आप टोकन के अंदर मेरी जानकारी पर क्लिक जा रहा> एपीआई करके प्राप्त कर सकते है आपका हाइराइज खाता

क्या यह सही है?

खैर वैसे भी, मैं इस जानकारी दर्ज करें और स्क्रिप्ट एक गंभीर त्रुटि और इस संदेश के साथ समाप्त हो जाता है:

Fatal error: Uncaught exception 'Exception' with message 'API for User returned Status Code: 0 Expected Code: 200' in /Users/me/Sites/sandbox/PHP/highrise_api_class/lib/HighriseAPI.class.php:137 
Stack trace: 
#0 /Users/me/Sites/sandbox/PHP/highrise_api_class/lib/HighriseAPI.class.php(166): HighriseAPI->checkForErrors('User') 
#1 /Users/me/Sites/sandbox/PHP/highrise_api_class/test/users.test.php(13): HighriseAPI->findMe() 
#2 {main} 
    thrown in /Users/me/Sites/sandbox/PHP/highrise_api_class/lib/HighriseAPI.class.php on line 137 

मैं पूरा n00b हूँ और मैं वास्तव में समझ में नहीं आता क्या यह इतना कह रहा है मैं यदि कोई सोच रहा था मदद कर सका। इसकी बहुत सराहना की जाएगी।

परीक्षण स्क्रिप्ट (users.test.php) का स्रोत है:

<?php 
require_once("../lib/HighriseAPI.class.php"); 

if (count($argv) != 3) 
    die("Usage: php users.test.php [account-name] [access-token]\n"); 

$hr = new HighriseAPI(); 
$hr->debug = false; 
$hr->setAccount($argv[1]); 
$hr->setToken($argv[2]); 

print "Finding my user...\n"; 
$user = $hr->findMe(); 
print_r($user); 

print "Finding all users...\n"; 
$users = $hr->findAllUsers(); 
print_r($users); 

?> 

और Highrise एपीआई आवरण फ़ाइल (Highrise.API.class) के लिए स्रोत है:

<?php 

    /* 
     * http://developer.37signals.com/highrise/people 
     * 
     * TODO LIST: 
     * Add Tasks support 
     * Get comments for Notes/Emails 
     * findPeopleByTagName 
     * Get Company Name, etc proxy 
     * Convenience methods for saving Notes $person->saveNotes() to check if notes were modified, etc. 
     * Add Tags to Person 
    */ 

    class HighriseAPI 
    { 
     public $account; 
     public $token; 
     protected $curl; 
     public $debug; 

     public function __construct() 
     { 
      $this->curl = curl_init(); 
      curl_setopt($this->curl,CURLOPT_RETURNTRANSFER,true); 

     curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml')); 
      // curl_setopt($curl,CURLOPT_POST,true); 
      curl_setopt($this->curl,CURLOPT_SSL_VERIFYPEER,0); 
      curl_setopt($this->curl,CURLOPT_SSL_VERIFYHOST,0); 
     } 

     public function setAccount($account) 
     { 
      $this->account = $account; 
     } 

     public function setToken($token) 
     { 
      $this->token = $token; 
      curl_setopt($this->curl,CURLOPT_USERPWD,$this->token.':x'); 
     } 

     protected function postDataWithVerb($path, $request_body, $verb = "POST") 
     { 
      $this->curl = curl_init(); 

      $url = "https://" . $this->account . ".highrisehq.com" . $path; 

      if ($this->debug) 
       print "postDataWithVerb $verb $url ============================\n"; 


      curl_setopt($this->curl, CURLOPT_URL,$url); 
      curl_setopt($this->curl, CURLOPT_POSTFIELDS, $request_body); 
      if ($this->debug == true) 
       curl_setopt($this->curl, CURLOPT_VERBOSE, true); 

      curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml')); 
      curl_setopt($this->curl, CURLOPT_USERPWD,$this->token.':x'); 
      curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER,0); 
      curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST,0); 
      curl_setopt($this->curl, CURLOPT_RETURNTRANSFER,true); 


      if ($verb != "POST") 
       curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $verb); 
      else 
       curl_setopt($this->curl, CURLOPT_POST, true); 

      $ret = curl_exec($this->curl); 

      if ($this->debug == true) 
       print "Begin Request Body ============================\n" . $request_body . "End Request Body ==============================\n"; 

      curl_setopt($this->curl,CURLOPT_HTTPGET, true); 

      return $ret; 
     } 

     protected function getURL($path) 
     { 
      curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml')); 
      curl_setopt($this->curl, CURLOPT_USERPWD,$this->token.':x'); 
      curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER,0); 
      curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST,0); 
      curl_setopt($this->curl, CURLOPT_RETURNTRANSFER,true); 

      $url = "https://" . $this->account . ".highrisehq.com" . $path; 

      if ($this->debug == true) 
       curl_setopt($this->curl, CURLOPT_VERBOSE, true); 


      curl_setopt($this->curl,CURLOPT_URL,$url); 
      $response = curl_exec($this->curl); 

      if ($this->debug == true) 
       print "Response: =============\n" . $response . "============\n"; 

      return $response; 

     } 

     protected function getLastReturnStatus() 
     { 
      return curl_getinfo($this->curl, CURLINFO_HTTP_CODE); 
     } 

     protected function getXMLObjectForUrl($url) 
     { 
      $xml = $this->getURL($url); 
      $xml_object = simplexml_load_string($xml); 
      return $xml_object; 
     } 

     protected function checkForErrors($type, $expected_status_codes = 200) 
     { 
      if (!is_array($expected_status_codes)) 
       $expected_status_codes = array($expected_status_codes); 

      if (!in_array($this->getLastReturnStatus(), $expected_status_codes)) 
      { 
       switch($this->getLastReturnStatus()) 
       { 
        case 404: 
         throw new Exception("$type not found"); 
         break; 
        case 403: 
         throw new Exception("Access denied to $type resource"); 
         break; 
        case 507: 
         throw new Exception("Cannot create $type: Insufficient storage in your Highrise Account"); 
         break; 

        default: 
         throw new Exception("API for $type returned Status Code: " . $this->getLastReturnStatus() . " Expected Code: " . implode(",", $expected_status_codes)); 
         break; 
       }    
      } 
     } 

     /* Users */ 

     public function findAllUsers() 
     { 
      $xml = $this->getUrl("/users.xml"); 
      $this->checkForErrors("User"); 

      $xml_object = simplexml_load_string($xml); 

      $ret = array(); 
      foreach($xml_object->user as $xml_user) 
      { 
       $user = new HighriseUser(); 
       $user->loadFromXMLObject($xml_user); 
       $ret[] = $user; 
      } 

      return $ret; 
     } 

     public function findMe() 
     { 
      $xml = $this->getUrl("/me.xml"); 
      $this->checkForErrors("User"); 

      $xml_obj = simplexml_load_string($xml); 
      $user = new HighriseUser(); 
      $user->loadFromXMLObject($xml_obj); 
      return $user; 
     } 

     /* Tasks */ 

     public function findCompletedTasks() 
     { 
      $xml = $this->getUrl("/tasks/completed.xml"); 
      $this->checkForErrors("Tasks"); 
      return $this->parseTasks($xml); 
     } 

     public function findAssignedTasks() 
     { 
      $xml = $this->getUrl("/tasks/assigned.xml"); 
      $this->checkForErrors("Tasks"); 
      return $this->parseTasks($xml); 
     } 


     public function findUpcomingTasks() 
     { 
      $xml = $this->getUrl("/tasks/upcoming.xml"); 
      $this->checkForErrors("Tasks"); 
      return $this->parseTasks($xml); 
     } 

     private function parseTasks($xml) 
     { 
      $xml_object = simplexml_load_string($xml);   
      $ret = array(); 
      foreach($xml_object->task as $xml_task) 
      { 
       $task = new HighriseTask($this); 
       $task->loadFromXMLObject($xml_task); 
       $ret[] = $task; 
      } 

      return $ret; 

     } 

     public function findTaskById($id) 
     { 
      $xml = $this->getURL("/tasks/$id.xml"); 
      $this->checkForErrors("Task"); 
      $task_xml = simplexml_load_string($xml); 
      $task = new HighriseTask($this); 
      $task->loadFromXMLObject($task_xml); 
      return $task; 

     } 

     /* Notes & Emails */ 

     public function findEmailById($id) 
     { 
      $xml = $this->getURL("/emails/$id.xml"); 
      $this->checkForErrors("Email"); 
      $email_xml = simplexml_load_string($xml); 
      $email = new HighriseEmail($this); 
      $email->loadFromXMLObject($email_xml); 
      return $email; 
     } 

     public function findNoteById($id) 
     { 
      $xml = $this->getURL("/notes/$id.xml"); 
      $this->checkForErrors("Note"); 
      $note_xml = simplexml_load_string($xml); 
      $note = new HighriseNote($this); 
      $note->loadFromXMLObject($note_xml); 
      return $note; 
     } 

     public function findPersonById($id) 
     { 
      $xml = $this->getURL("/people/$id.xml"); 

      $this->checkForErrors("Person"); 


      $xml_object = simplexml_load_string($xml); 

      $person = new HighrisePerson($this); 
      $person->loadFromXMLObject($xml_object); 
      return $person; 
     } 

     public function findAllTags() 
     { 
      $xml = $this->getUrl("/tags.xml"); 
      $this->checkForErrors("Tags"); 

      $xml_object = simplexml_load_string($xml);   
      $ret = array(); 
      foreach($xml_object->tag as $tag) 
      { 
       $ret[(string)$tag->name] = new HighriseTag((string)$tag->id, (string)$tag->name); 
      } 

      return $ret; 
     } 

     public function findAllPeople() 
     { 
      return $this->parsePeopleListing("/people.xml");  
     } 

     public function findPeopleByTagName($tag_name) 
     { 
      $tags = $this->findAllTags(); 
      foreach($tags as $tag) 
      { 
       if ($tag->name == $tag_name) 
        $tag_id = $tag->id; 
      } 

      if (!isset($tag_id)) 
       throw new Excepcion("Tag $tag_name not found"); 

      return $this->findPeopleByTagId($tag_id); 
     } 

     public function findPeopleByTagId($tag_id) 
     { 
      $url = "/people.xml?tag_id=" . $tag_id; 
      $people = $this->parsePeopleListing($url); 
      return $people; 
     } 

     public function findPeopleByEmail($email) 
     { 
     return $this->findPeopleBySearchCriteria(array("email"=>$email)); 
     } 

     public function findPeopleByTitle($title) 
     { 
      $url = "/people.xml?title=" . urlencode($title); 

      $people = $this->parsePeopleListing($url); 
      return $people; 
     } 



     public function findPeopleByCompanyId($company_id) 
     { 
      $url = "/companies/" . urlencode($company_id) . "/people.xml"; 
      $people = $this->parsePeopleListing($url); 
      return $people; 
     } 

     public function findPeopleBySearchTerm($search_term) 
     { 
      $url = "/people/search.xml?term=" . urlencode($search_term); 
      $people = $this->parsePeopleListing($url, 25); 
      return $people; 
     } 

     public function findPeopleBySearchCriteria($search_criteria) 
     { 
      $url = "/people/search.xml"; 

      $sep = "?"; 
      foreach($search_criteria as $criteria=>$value) 
      { 
       $url .= $sep . "criteria[" . urlencode($criteria) . "]=" . urlencode($value); 
       $sep = "&"; 
      } 

      $people = $this->parsePeopleListing($url, 25); 
      return $people; 
     } 

     public function findPeopleSinceTime($time) 
     { 
      $url = "/people/search.xml?since=" . urlencode($time); 
      $people = $this->parsePeopleListing($url); 
      return $people; 
     } 
     public function parsePeopleListing($url, $paging_results = 500) 
     { 
      if (strstr($url, "?")) 
       $sep = "&"; 
      else 
       $sep = "?"; 

      $offset = 0; 
      $return = array(); 
      while(true) // pagination 
      { 
       $xml_url = $url . $sep . "n=$offset"; 
       // print $xml_url; 
       $xml = $this->getUrl($xml_url); 
       $this->checkForErrors("People"); 
       $xml_object = simplexml_load_string($xml); 

       foreach($xml_object->person as $xml_person) 
       { 
        // print_r($xml_person); 
        $person = new HighrisePerson($this); 
        $person->loadFromXMLObject($xml_person); 
        $return[] = $person; 
       } 

       if (count($xml_object) != $paging_results) 
        break; 

       $offset += $paging_results; 
      } 

      return $return; 
     } 

    } 

क्षमा करें यह इतनी लंबी फ़ाइल है लेकिन अगर यह मदद करता है, तो हो सकता है।

संपादित करें: तो मुझे लगता है कि मुझे यह काम करने के लिए मिला है। मुझे यह कहना चाहिए था कि मैं अपने स्थानीय सर्वर पर इस लाइब्रेरी का परीक्षण करने की कोशिश कर रहा था और किसी कारण से यह असफल रहेगा, लेकिन जब मैंने स्क्रिप्ट को अपने विकास सर्वर पर रैकस्पेस क्लाउड पर ले जाया तो यह काम करेगा। यह सिर्फ मुझे पहेली करता है। दोनों सर्वरों के पास PHP कर्ल के लिए समर्थन है, इसलिए मैं वास्तव में समझ नहीं पा रहा हूं कि समस्या कहां है।

संपादित करें: मुझे यकीन है कि क्या दो सर्वर विन्यास के बीच का अंतर हो सकता है नहीं कर रहा हूँ, लेकिन वैसे भी यहां मेरे कर्ल विन्यास के दोनों सर्वर से मेरी phpinfo समारोह उत्पादन से स्क्रीनशॉट की एक जोड़ी है:

स्थानीय होस्ट सर्वर:

enter image description here

और रैकस्पेस बादल सर्वर:

enter image description here

+0

क्या आपने http के साथ प्रयास किया है? आप किस संसाधन को प्राप्त करने की कोशिश कर रहे हैं (लोग, श्रेणियाँ ....) – jjchiw

+0

उम लोग मुझे लगता है। मैं बस यह देखने के लिए परीक्षण कर रहा हूं कि मेरे प्रमाण पत्र भी काम करते हैं या नहीं। Http के साथ प्रयास करके आपका क्या मतलब है? – racl101

उत्तर

1

आह, चूंकि वास्तव में कोई HTTP त्रुटि कोड नहीं है 0 मुझे उम्मीद है कि आपका अनुरोध हाइराइज़ की वेबसाइट पर नहीं किया जा रहा है, या आप कक्षा के खाते के नाम और टोकन में सही तरीके से गुजर नहीं रहे हैं। क्या आप अपने users.test.php कक्षा का स्रोत शामिल कर सकते हैं?

संपादित करें: कक्षा और आपके कोड का परीक्षण किया, और यह मेरे लिए काम करता है। आपने शायद लाइब्रेरी फ़ाइल को गलत तरीके से कॉपी किया है या आपके टोकन को गलत कॉपी किया है।

+0

इसलिए मैंने स्रोत कोड को शामिल करने के लिए प्रश्न बढ़ाया। – racl101

+0

क्या आप मुझे बता सकते हैं कि आपने अपने ब्राउज़र या टर्मिनल पर कोड का परीक्षण किया है और यदि आपने इसे अपने टर्मिनल पर परीक्षण किया है तो आपने आदेश कैसे कहा है (बेशक नकली टोकन मूल्यों और खाता नाम के साथ)? मैं अभी भी इसे काम नहीं कर सकता हूं और मुझे यह मेरे लिए काम करने की ज़रूरत है। किसी भी सहायता की सराहना की जाएगी। – racl101

+0

मुझे यह काम करने के लिए मिला लेकिन मेरे ऑनलाइन विकास सर्वर पर रैकस्पेस क्लाउड पर। देखें कि मैं इसे अपने लोकहोस्ट सर्वर पर परीक्षण करने की कोशिश कर रहा था और इससे कोई फर्क नहीं पड़ता कि मैंने क्या किया। – racl101

2

एपीआई का कांटा ... https://github.com/AppSaloon/Highrise-PHP-Api ... अधिक विकसित और बेहतर बनाए रखा लगता है।

उत्तर देने के लिए इतना कुछ नहीं, लेकिन एक बेहतर प्रारंभिक बिंदु।

+0

मैंने इस संस्करण का उपयोग किया क्योंकि मुझे कंपनी समर्थन की आवश्यकता थी। कोड संरचना के संदर्भ में यह मूल रूप से अधिक परिपक्व और पुन: कार्य करता है, हालांकि मुझे काम करने के लिए कस्टम फ़ील्ड समर्थन नहीं मिला। – bigendian

0

मुझे एक ही समस्या थी। मुझे निश्चित रूप से गलत खाता था। मेरे पास foo के बजाय https://foo.highrisehq.com था।

संबंधित मुद्दे