Joe*_*oel 16 php google-calendar-api
我正在尝试使用Google API v3访问一个Google日历,并根据此处的文档:http://code.google.com/apis/calendar/v3/using.html#intro和here: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;
}
Run Code Online (Sandbox Code Playgroud)
在我的"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',
Run Code Online (Sandbox Code Playgroud)
但后来我收到错误,它告诉我它正在尝试使用我不想使用的"OAuth 2.0"系统进行身份验证.我只想使用API密钥访问一个日历.
令人惊讶的是,当我在谷歌搜索"简单的API访问密钥"时,我什么也没找到,没有关于他们的文档,没有示例,没有教程,没有.我是唯一一个使用这个东西的人吗?
那么有人能告诉我我做错了什么吗?
(我知道这是一个古老的问题,但如果有人在这里给出了真正的答案,我会很高兴,所以我现在正在这样做)
我遇到了同样的问题,简单的API访问没有很好地记录(或者可能只是我搜索的地方),但使用Google API Explorer我找到了一种方法来获得我需要的东西,这实际上非常简单.你不需要特定的lib或任何东西:它实际上非常简单.
在我的情况下,我只需要在G +上搜索关键字,所以我只需要做一个GET请求:
https://www.googleapis.com/plus/v1/activities?query={KEYWORD}&key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)
现在,对于日历访问(请参阅此处),让我们假装我们想要获取访问控制规则列表.我们需要参考给我们提供URI的calendar.acl.list:
https://www.googleapis.com/calendar/v3/calendars/{CALENDAR_ID}/acl?key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)
填写空白,这几乎是你需要做的.获取服务器密钥(API Access子菜单),将其存储在项目中的某个位置,并在您请求的URI中调用它.
没有这样的东西叫做Simple API Access key。
通常使用OAuth 2.0进行授权。但既然你有理由不使用它。
API keyin部分。Simple API Access