Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php gcal类不工作_Php_Pear_Gcal - Fatal编程技术网

Php gcal类不工作

Php gcal类不工作,php,pear,gcal,Php,Pear,Gcal,Iam使用一个php类将事件添加到google calender。但该类在加载index.php页面时返回错误 这是index.php页面中iam调用类的代码: <?php require_once('gcal.class.php'); $g = new gcal('test@gmail.com','test123$'); $cal_url = 'https://www.google.com/calendar/feeds/test@gmail.com/private-01d281d910

Iam使用一个php类将事件添加到google calender。但该类在加载index.php页面时返回错误

这是index.php页面中iam调用类的代码:

<?php
require_once('gcal.class.php');
$g = new gcal('test@gmail.com','test123$'); 
$cal_url = 'https://www.google.com/calendar/feeds/test@gmail.com/private-01d281d910a2622c8c2f5899690b9eb5/basic'; 
$eTitle = 'test event'; $eDesc = 'Another Test'; $eAuthorName = 'Justin Burger'; $eAuthorEmail = 'justin@loudisrelative.com'; $eLocation = 'LIR Offices'; $eStartTime = date('c'); $eEndTime = date('c',strtotime("+1 hour")); 

//Adding an event.
$g->addEvent($cal_url,$eTitle, $eDesc, $eAuthorName, $eAuthorEmail,$eLocation,$eStartTime, $eEndTime); 

?>
我的代码中有什么问题

当我从谷歌代码下载这个类时,他们说,请确保在使用之前安装了这两个类(例如:pear install Net和pear install HTTP)。
我不知道怎么做?给我一个解决方案。

您需要安装HTTP\U请求包才能使其正常工作。包可以找到

请看这里
希望对您有所帮助

首先,如果“PEAR”文件夹存在,请检查您的“php”文件夹。如果没有,则安装PEAR(说明:)

如果是这样,如果参数“include_path”具有指向“PEAR”文件夹的绝对路径(例如,在Windows上:include_path=“;C:\xampp\php\PEAR”),请检查“php.ini”

问候
布朗克

 <?php
require_once('HTTP/Request.php');

    class gcal{
        /** Google Auth Token, used to authorize add functions*/
        private $token;

        /** Users Email Address (notice, password is not stored) */
        private $email;
        function __construct($email, $password){
            $this->login($email,$password); 
            $this->email = $email;      
        }
        public function addEvent($cal_url,$eTitle, $eDesc, $eAuthorName, $eAuthorEmail,$eLocation,$eStartTime, $eEndTime){
            /* Make sure we send ONLY valid XML. */
            $eTitle         = htmlentities($eTitle);
            $eDesc          = htmlentities($eDesc);
            $eAuthorName    = htmlentities($eAuthorName);
            $eAuthorEmail   = htmlentities($eAuthorEmail);
            $eLocation      = htmlentities($eLocation);
            $eStartTime     = htmlentities($eStartTime);
            $eEndTime       = htmlentities($eEndTime);

             $xml = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>
                <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'></category>
                <title type='text'>{$eTitle}</title>
                <content type='text'>{$eDesc}</content>
                <author>
                    <name>{$eAuthorName}</name>
                    <email>{$eAuthorEmail}</email>
                </author>
                <gd:transparency value='http://schemas.google.com/g/2005#event.opaque'></gd:transparency>
                <gd:eventStatus
                    value='http://schemas.google.com/g/2005#event.confirmed'>
                </gd:eventStatus>
                <gd:where valueString='{$eLocation}'></gd:where>
                <gd:when startTime='{$eStartTime}'
                    endTime='{$eEndTime}'></gd:when>
            </entry>";

            $http = new HTTP_Request($cal_url,array('allowRedirects' => true));
            $http->setMethod('POST');
            $http->addHeader('Host','www.google.com');
            $http->addHeader('MIME-Version','1.0');
            $http->addHeader('Accept','text/xml');
            $http->addHeader('Content-type','application/atom+xml');
            $http->addHeader('Authorization','GoogleLogin auth=' . $this->token);
            $http->addHeader('Content-length',strlen($xml));
            $http->addHeader('Cache-Control','no-cache');
            $http->addHeader('Connection','close');
            $http->setBody($xml);
            $http->sendRequest();

            switch($http->getResponseCode()){
                case 201: case 200:
                    return true;
                    break;
                default:
                    throw new Exception('Error Adding Google Cal Event. Response From Google:' . $http->getResponseBody(), $http->getResponseCode());
                    return false;
                    break;  
            }

        }

        public function getCalendarList(){
            $url = 'http://www.google.com/calendar/feeds/' . $this->email;

            $http = new HTTP_Request($url,array('allowRedirects' => true));
            $http->addHeader('Authorization','GoogleLogin auth=' . $this->token);
            $http->setMethod('GET');
            $http->sendRequest();
            $xml = new SimpleXMLElement($http->getResponseBody());

            $calendars = array();
            foreach ($xml->entry as $cal){

                foreach($cal->link as $key=>$link){
                    $linkSets = array();
                    $links = $link->attributes();
                    $links = (array) $links;
                    foreach($links as $l){
                        $linkSets[] = array('rel'=>$l['rel'],
                                            'type'=>$l['type'],
                                            'href'=>$l['href']);
                    }
                }
                $calendars[] = array('id'=>strval($cal->id),
                                     'published'=>strval($cal->published),
                                     'updated'=>strval($cal->updated),
                                     'title'=>strval($cal->title),
                                     'authorName'=>strval($cal->author->name),
                                     'authorEmail'=>strval($cal->author->email),
                                     'links'=>$linkSets);
            }
            return $calendars;
        }
        private function login($email, $password){
            $url = 'https://www.google.com/accounts/ClientLogin';


            $http = new HTTP_Request('https://www.google.com/accounts/ClientLogin',
                                     array('allowRedirects' => true));
            $http->setMethod('POST');
            $http->addPostData('Email', $email);
            $http->addPostData('Passwd', $password);
            $http->addPostData('source', 'example-test-2');
            $http->addPostData('service', 'cl');
            $http->addPostData('accountType', 'HOSTED_OR_GOOGLE');
            $http->sendRequest();

            switch($http->getResponseCode()){
                case 403:
                    throw new Exception('Google Auth Failed',403);
                    break;
                case 200: case 201:
                    $this->token = $this->extractAuth($http->getResponseBody());
                    return true;
                    break;
                default:
                    throw new Exception('Unknown Google Auth Failure',$http->getResponseCode());
                    break;  
            }
        }

        private function extractAuth($body){
            $st = strpos($body,'Auth=');
            $token = trim(substr($body,($st+5)));
            return $token;
        }
    }

?>
Warning: require_once(HTTP/Request.php) [function.require-once]: failed to open stream: No such file or directory in E:\wamp\www\gcal\gcal.class.php on line 2
Fatal error: require_once() [function.require]: Failed opening required 'HTTP/Request.php' (include_path='.;C:\php\pear') in E:\wamp\www\gcal\gcal.class.php on line 2