如何使用Google的“简单API访问密钥"访问Google日历信息(PHP)? [英] How do I use Google's "Simple API Access key" to access Google Calendar info (PHP)?

查看:193
本文介绍了如何使用Google的“简单API访问密钥"访问Google日历信息(PHP)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google API v3访问一个Google日历,并根据此处的文档进行操作: http://code.google.com/apis/calendar/v3/using.html#intro 以及此处:

I'm trying to use the Google API v3 to access one google calendar and according to the documentation here : http://code.google.com/apis/calendar/v3/using.html#intro and here : https://code.google.com/apis/console/, the solution I need is the "Simple API Access" & "Key for server apps (with IP locking)".

现在,当我使用以下代码创建页面时:

Now, when I create a page with this code :

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"):

and in my "config.php" file I add ONLY my developper key (in place of the "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​​密钥访问一个日历.

But then I get errors and it tells me it's trying to authenticate using the "OAuth 2.0" system which I don't want to use. I only want to access one calendar with an API key.

而且令人惊讶的是,当我在Google中搜索简单API访问密钥"时,我什么也没找到,他们的文档也没有找到任何内容,没有示例,也没有教程,也没有找到任何东西.我是唯一使用这个东西的人吗?

And amazingly, when I search in google "Simple API Access key" I find nothing, nothing on their docs, no examples, no tutorials, nothing. Am I the only one using this thing?

那么有人可以告诉我我在做什么错吗?

So can someone tell me what I'm doing wrong?

推荐答案

(我知道这是一个老问题,但是如果有人 在这里给出了一个真实的答案,所以我现在就开始做

(i know this is an old question but i would've been glad if someone gave a real answer here so i'm doing it now)

我遇到了同样的问题,简单的API访问没有得到很好的文档记录(或者可能不是我搜索的位置),而是使用了

I came on the same problem, Simple API access is not well documented (or maybe just not where i searched), but using the Google API Explorer i found a way to get what i need, which is in fact pretty straightforward. You don't need specific lib or anything : it's actually really simple.

就我而言,我只需要搜索G +上的关键字,因此我只需要执行GET请求:

In my case i simply needed to search a keyword on G+, so i just had to do a GET request:

https://www.googleapis.com/plus/v1/activities?query={KEYWORD}&key={YOUR_API_KEY}

现在,要进行日历访问(请参见此处) ,让我们假设要获取访问控制规则列表.我们需要参考 calendar.acl.list 为我们提供URI:

Now, for a calendar access (see here), let's pretend we want to fetch access control rules list. We need to refer to calendar.acl.list which give us the URI :

https://www.googleapis.com/calendar/v3/calendars/{CALENDAR_ID}/acl?key={YOUR_API_KEY}

填补空白,这几乎是您需要做的所有事情.获取服务器密钥(API访问子菜单),将其存储在项目中的某个位置,然后在您请求的URI.

Fill in the blanks, and that's pretty much all you need to do. Get a server key (API Access submenu), store it somewhere in your project and call it within URIs you're requesting.

这篇关于如何使用Google的“简单API访问密钥"访问Google日历信息(PHP)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆