首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >似乎无法正确安装google-api-php-client。

似乎无法正确安装google-api-php-client。
EN

Stack Overflow用户
提问于 2016-02-03 13:53:43
回答 1查看 674关注 0票数 0

google客户端出了问题。尽管我跟踪了github上的安装,但它仍然无法工作。我不使用作曲家的方式,但我下载了发行版。我尝试在响应-callback.php require_once中使用不同的路径,如

代码语言:javascript
复制
'google-api-php-client/src/google/autoload.php'
'google-api-php-client/vendor_autoload.php' 

但什么都没用..。

错误:

代码语言:javascript
复制
Fatal error: require_once(): Failed opening required 'google-api-php-client/vendor/autoload.php' (include_path='.:/Users/mike/Documents/test:/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/php/sdk') in /Users/mike/Documents/test/response-callback.php on line 3
Warning: require_once(google-api-php-client/vendor/autoload.php): failed to open stream: No such file or directory in /Users/mike/Documents/test/response-callback.php on line 3

app.yaml:

代码语言:javascript
复制
application: csimporttest
version: 1
runtime: php55
api_version: 1

handlers:
- url: /.*
  script: main.php

main.php

代码语言:javascript
复制
<!DOCTYPE html>
<html>

<head>
</head>

<body>
<h2>Hi! Stackoverflow!</h2>

<?php include'response-callback.php';
echo "response-callback file: ", $test; 

?>
<a href="<?php include'response-callback.php'; echo $googleImportUrl; ?>"> Import google contacts </a>
</body>

</html>

response-callback.php

代码语言:javascript
复制
<?php

require_once 'google-api-php-client/vendor/autoload.php';

$test = 'WORKS!'; 

$google_client_id = 'SECRET';
$google_client_secret = 'SECRET';
$google_redirect_uri = 'https://csimporttest.appspot.com';

//setup new google client
$client = new Google_Client();
$client -> setApplicationName('csimporttest');
$client -> setClientid($google_client_id);
$client -> setClientSecret($google_client_secret);
$client -> setRedirectUri($google_redirect_uri);
$client -> setAccessType('online');

$client -> setScopes('https://www.googleapis.com/auth/contacts.readonly');

$googleImportUrl = $client -> createAuthUrl();
function curl($url, $post = "") {
 $curl = curl_init();
 $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
 curl_setopt($curl, CURLOPT_URL, $url);
 //The URL to fetch. This can also be set when initializing a session with curl_init().
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
 //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
 curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
 //The number of seconds to wait while trying to connect.
 if ($post != "") {
 curl_setopt($curl, CURLOPT_POST, 5);
 curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
 }
 curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
 //The contents of the "User-Agent: " header to be used in a HTTP request.
 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
 //To follow any "Location: " header that the server sends as part of the HTTP header.
 curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE);
 //To automatically set the Referer: field in requests where it follows a Location: redirect.
 curl_setopt($curl, CURLOPT_TIMEOUT, 10);
 //The maximum number of seconds to allow cURL functions to execute.
 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
 //To stop cURL from verifying the peer's certificate.
 $contents = curl_exec($curl);
 curl_close($curl);
 return $contents;
}
if(isset($_SESSION['google_code'])) {
 $auth_code = $_SESSION['google_code'];
 $max_results = 200;
    $fields=array(
        'code'=>  urlencode($auth_code),
        'client_id'=>  urlencode($google_client_id),
        'client_secret'=>  urlencode($google_client_secret),
        'redirect_uri'=>  urlencode($google_redirect_uri),
        'grant_type'=>  urlencode('authorization_code')
    );
    $post = '';
    foreach($fields as $key=>$value)
    {
        $post .= $key.'='.$value.'&';
    }
    $post = rtrim($post,'&');
    $result = curl('https://www.googleapis.com/oauth2/v4/token',$post);
    $response =  json_decode($result);
    $accesstoken = $response->access_token;
    $url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$accesstoken;
    $xmlresponse =  curl($url);
    $contacts = json_decode($xmlresponse,true);

 $return = array();
 if (!empty($contacts['feed']['entry'])) {
 foreach($contacts['feed']['entry'] as $contact) {
           //retrieve Name and email address  
 $return[] = array (
 'name'=> $contact['title']['$t'],
 'email' => $contact['gd$email'][0]['address'],
 );
 } 
 }

 $google_contacts = $return;

 unset($_SESSION['google_code']);

}
?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-12 09:15:45

只需将整个Google php客户端库放在项目文件夹中,然后更改

代码语言:javascript
复制
require_once 'google-api-php-client/vendor/autoload.php';

至:

代码语言:javascript
复制
require_once 'google-api-php-client-1-master/src/Google/autoload.php';
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35178986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档