有人使用过此Highrise API PHP包装器库吗?我需要身份验证帮助

如何解决有人使用过此Highrise API PHP包装器库吗?我需要身份验证帮助

| 所以我从这个github链接下载了一个包装器类: https://github.com/ignaciovazquez/Highrise-PHP-Api 而我只是想获得任何回应。到目前为止,我什至无法使用我的凭据进行身份验证,因此我想知道是否有使用过该API的人可以帮助我。 我尝试在Terminal上不带任何参数运行测试文件之一,这就是告诉我的内容:
Usage: php users.test.php [account-name] [access-token]
好了,于是决定决定获取我的证书。因此,这是我的理解,如果我错了,请更正: 帐户名称是指向您的高层帐户网址的那一部分。因此,如果您的网址是: https://exampleaccount.highrisehq.com/ 那么您的帐户名称是:\“ exampleaccount \” 您的访问令牌就是您的身份验证令牌,可以通过在Highrise帐户中单击我的信息> API令牌来找到。 那正确吗? 好吧,无论如何,我输入此信息,脚本以致命错误和以下消息终止:
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 API包装文件(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,\'Content-Type: application/xml\'));
          curl_setopt($this->curl,$this->token.\':x\');
            curl_setopt($this->curl,true);


            if ($verb != \"POST\")
              curl_setopt($this->curl,CURLOPT_CUSTOMREQUEST,$verb);
            else
                curl_setopt($this->curl,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,true);

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

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


            curl_setopt($this->curl,$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;
        }

    }
抱歉,文件太长了,但是如果有帮助的话,就这样吧。 编辑:所以我想我明白了。我应该说,我正在尝试在本地服务器上测试该库,由于某种原因,它会一直失败,但是当我将脚本移至Rackspace云上的开发服务器时,它将可以正常工作。这让我感到困惑。两台服务器均支持PHP curl,因此我无法真正理解问题所在。 编辑:我不确定这两个服务器配置之间可能有什么区别,但是无论如何,这是我的curl配置的两个服务器的phpinfo函数输出的一些屏幕截图: Localhost服务器: 和机架云服务器:     

解决方法

嗯,因为实际上没有HTTP错误代码0,所以我希望您的请求没有发送到Highrise \的网站,或者您没有正确将帐户名和令牌传递给该类。可以包括您的
users.test.php
班级的资料吗? 编辑:测试了类和您的代码,它为我工作。您可能复制了错误的库文件,或者复制了错误的令牌。     ,API的分支在... https://github.com/AppSaloon/Highrise-PHP-Api ...似乎更发达,维护更好。 与其说是提供答案,不如说是一个更好的起点。     ,我遇到过同样的问题。我肯定有错误的帐户。我只有5英镑,而不仅仅是6英镑。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-