我正在使用 Google API 的 PHP 客户端来访问 gmail 联系人。我的代码在 localhost 中运行良好,但是当我将其移至托管服务时它停止工作。是的,我确实验证了所有 oauth 参数并在 Google API 控制台中更新了相同的参数。
有没有办法调试它?我正在使用codeigniter 2.1。
config.php -
$config['uri_protocol']= 'AUTO';
并在控制器方法中添加parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
if 条件。然后来自 [博客][1]。config.php -
$config['uri_protocol'] = "PATH_INFO";
和控制器方法与parse_str($_SERVER['QUERY_STRING'], $_GET);
之前的 if 条件。
控制器方法是
function gmail_invite()
{
session_start();
$gmailContacts = array();
$client = new Google_Client();
$client->setApplicationName('tets');
$client->setScopes("http://www.google.com/m8/feeds/");
$client->setClientId('222222.apps.googleusercontent.com');
$client->setClientSecret('secret');
$client->setRedirectUri('http://testsite.com/gmail_invite');
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if (isset($_REQUEST['logout'])) {
unset($_SESSION['token']);
$client->revokeToken();
}
if ($client->getAccessToken()) {
$req = new Google_HttpRequest("https://www.google.com/m8/feeds/contacts/default/full?max-results=500");
$val = $client->getIo()->authenticatedRequest($req);
$xml = simplexml_load_string($val->getResponseBody());
$result = $xml->xpath('//gd:email');
//print "<pre>" .print_r($result,false). "</pre>";
foreach ($result as $title) {
array_push($gmailContacts, mysql_real_escape_string($title->attributes()->address));
}
// The contacts api only returns XML responses.
//$response = json_encode(simplexml_load_string($val->getResponseBody()));
//print "<pre>" . print_r(json_decode($response, true), true) . "</pre>";
// The access token may have been updated lazily.
$_SESSION['token'] = $client->getAccessToken();
} else {
redirect($client->createAuthUrl());
}
配置文件
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd'; // experimental not currently in use
$config['log_threshold'] = 4;
$config['log_path'] = '';
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['cache_path'] = '';
$config['encryption_key'] = '';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;
$config['global_xss_filtering'] = FALSE;
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';
/* End of file config.php */
/* Location: ./application/config/config.php */