【发布时间】:2012-01-06 10:41:17
【问题描述】:
我正在尝试使用 Google API v3 访问一个谷歌日历,并根据此处的文档:http://code.google.com/apis/calendar/v3/using.html#intro 和此处:https://code.google.com/apis/console/,我需要的解决方案是“简单 API 访问”和“用于服务器应用程序(带有 IP 锁定)”。
现在,当我使用此代码创建页面时:
session_start();
require_once 'fnc/google-api-php-client/src/apiClient.php';
require_once 'fnc/google-api-php-client/src/contrib/apiCalendarService.php';
$apiClient = new apiClient();
$apiClient->setUseObjects(true);
$service = new apiCalendarService($apiClient);
if (isset($_SESSION['oauth_access_token'])) {$apiClient->setAccessToken($_SESSION['oauth_access_token']);
} else {
$token = $apiClient->authenticate();
$_SESSION['oauth_access_token'] = $token;
}
在我的“config.php”文件中,我只添加了我的开发者密钥(代替“X”):
global $apiConfig;
$apiConfig = array(
// True if objects should be returned by the service classes.
// False if associative arrays should be returned (default behavior).
'use_objects' => false,
// The application_name is included in the User-Agent HTTP header.
'application_name' => '',
// OAuth2 Settings, you can get these keys at https://code.google.com/apis/console
'oauth2_client_id' => '',
'oauth2_client_secret' => '',
'oauth2_redirect_uri' => '',
// The developer key, you get this at https://code.google.com/apis/console
'developer_key' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
// OAuth1 Settings.
// If you're using the apiOAuth auth class, it will use these values for the oauth consumer key and secret.
// See http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html for info on how to obtain those
'oauth_consumer_key' => 'anonymous',
'oauth_consumer_secret' => 'anonymous',
但后来我收到错误,它告诉我它正在尝试使用我不想使用的“OAuth 2.0”系统进行身份验证。我只想使用 API 密钥访问一个日历。
令人惊讶的是,当我在谷歌搜索“简单 API 访问密钥”时,我什么也没找到,他们的文档上什么都没有,没有示例,没有教程,什么都没有。我是唯一一个使用这个东西的人吗?
那么谁能告诉我我做错了什么?
【问题讨论】:
-
这里也一样......你去哪儿了吗?
-
出于好奇 - 您是否将服务器的 IP 添加到“简单 API 访问”对话框下的允许 IP 地址列表中?
-
我也有同样的情况。有人解决了吗?