我google-api-php-client用于获取和插入 Google 日历事件。现在我想将系统上的事件与 Google 日历上的事件同步。
我想知道,如果我在 Google 日历中添加事件,它是否可以自动添加到我的系统中(可能带有一些回调 url),所以我不需要使用 CRON 作业在某个时间间隔内重新检查 Google 日历中的事件?
谢谢!
我在尝试使用https://code.google.com/p/google-api-php-client/上的php客户端从Google云端存储下载文件时遇到问题
我已经验证了自己的确定并使用以下代码我可以返回一个包含我的文件的链接的对象
$this->storageService = new Google_StorageService($this->client);
$this->objects = $this->storageService->objects;
$options = array(
'prefix' => 'REPORT_NAME_2013-07-01'
);
$bucket_contents = $this->objects->listObjects($bucket, $options);
Run Code Online (Sandbox Code Playgroud)
回应就像......
{
"kind": "storage#object",
"id": "<bucket>/<report>.csv/1001",
"selfLink": "https://www.googleapis.com/storage/v1beta2/b/<bucket>/o/<report>.csv",
"name": "<report>.csv",
"bucket": "<bucket>",
"generation": "1001",
"metageneration": "1",
"contentType": "application/csv",
"updated": "2013-07-22T10:21:08.811Z",
"size": "806",
"md5Hash": "wT01i....",
"mediaLink": "https://www.googleapis.com/storage/v1beta2/b/<bucket>/o/<report>.csv?generation=1001&alt=media",
"owner": {
"entity": "user-00b........",
"entityId": "00b490......."
},
"crc32c": "8y........",
"etag": "CPjZ.........."
}
Run Code Online (Sandbox Code Playgroud)
但是如何使用Google PHP客户端下载文件...我不能使用file_get_contents,因为它不知道身份验证详细信息.我发现的最好的东西是使用Google_Client,但响应只包含元数据而没有对象/文件内容
$request = new Google_HttpRequest($object['selfLink']);
$response = $this->client->getIo()->authenticatedRequest($request);
Run Code Online (Sandbox Code Playgroud) 我有一段时间试图使用 Google 日历 API 将一个非常简单的事件添加到日历中,如果有人能指出我的(可能很明显的)问题,我会很高兴的。我正在使用我在这里找到的代码。我已经把代码放在“google-api-php-client/examples.calendar”目录下,在那里可以找到一个简单的例子。
<?php
require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_CalendarService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");
$client->setClientId('');
$client->setClientSecret('');
$client->setRedirectUri('worked.html'); //I made a file called "worked.html" in the same directory that just says "it worked!"
$client->setDeveloperKey('SecretLongDeveloperKey');
$cal = new Google_CalendarService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$authUrl = $client->createAuthUrl();
if (!$client->getAccessToken()){
$event = new Google_Event();
$event->setSummary('Halloween');
$event->setLocation('The …Run Code Online (Sandbox Code Playgroud) 我在多个页面上使用 Google API 时遇到问题。来自 Google 的示例工作正常,但所有代码都在一页上。
我有两页。第一页,用户点击登录按钮,第二页,我使用 google api 拉取用户信息。
第一页:
<?php
########## Google Settings.. Client ID, Client Secret from https://cloud.google.com/console #############
$google_client_id = 'myid';
$google_client_secret = 'mysecret';
$google_redirect_url = 'http://www.myWebsite.com/secondPage.php'; //path to your script
$google_developer_key = 'mydeveloperkey';
//include google api files
require_once '../includes/Google/autoload.php';
//start session
session_start();
$client = new Google_Client();
$client->setClientId($google_client_id);
$client->setClientSecret($google_client_secret);
$client->setRedirectUri($google_redirect_url);
$client->addScope("https://www.googleapis.com/auth/drive");
$client->addScope("https://www.googleapis.com/auth/calendar");
$client->addScope("https://www.googleapis.com/auth/gmail.compose");
$client->addScope("https://www.googleapis.com/auth/plus.me");
$drive_service = new Google_Service_Drive($client);
$calendar_service = new Google_Service_Calendar($client);
$gmail_service = new Google_Service_Gmail($client);
/************************************************
If we're logging out we just need …Run Code Online (Sandbox Code Playgroud) 我想在codeigniter中使用php上传文件到谷歌驱动器.首先,我正在尝试将google api客户端集成到codiginator.
我已将所有文件上传到我的third_party文件夹中.它看起来像这样
我google.php在我的libraries文件夹中创建了一个文件
google.php文件
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
set_include_path(APPPATH . 'third_party/' . PATH_SEPARATOR . get_include_path());
require_once APPPATH . 'third_party/Google/Client.php';
class Google extends Google_Client {
function __construct($params = array()) {
parent::__construct();
}
}
?>
Run Code Online (Sandbox Code Playgroud)
然后我像这样在我的家庭控制器中加载了库
function __construct() {
parent::__construct();
//session, url, satabase is set in auto load in the config
$this->load->model('Home_model', 'home');
$this->load->library('pagination');
$this->load->library('google');
}
Run Code Online (Sandbox Code Playgroud)
加载谷歌库后,家庭控制器内的所有功能都无法正常工作.每件事只显示一个空白页面.
在家庭控制器内部我有一个'test_lib'功能
function test_lib(){
echo $this->google->getLibraryVersion();
}
Run Code Online (Sandbox Code Playgroud)
当我加载页面.我得到一个黑页没有错误或显示.
有人可以帮助我将google api客户端库添加到codeigniter.TNX.
注意:这个问题被标记为 13413036 的可能重复。事实并非如此,在那个问题中,他们询问如何使用可恢复上传来上传文件。这段代码正是这样做的,而且它有效。唯一的问题是库在长时间后崩溃。
我正在尝试将 40GB 的文件从 Cloud Compute 实例上传到 Drive。
我有一个在命令行上运行的 PHP 脚本,它在大约一个小时后崩溃。
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling PUT https://www.goog
leapis.com/upload/drive/v2/files?uploadType=resumable&upload_id=AEnB2UrkY_dh7-GmPp33joiPzhBT3DHY6fg4bgN_PNWVgEYg
IBZmFf0UceJbLS1XeyaJ0bFxdMTNWtPVEAQKIf8uE7HBExuG6g: (503) Service Unavailable' in /var/www/backend/phpsdk/exampl
es/apiClient/src/Google/Http/REST.php:110
Stack trace:
#0 /var/www/backend/phpsdk/examples/apiClient/src/Google/Http/MediaFileUpload.php(183): Google_Http_REST::decode
HttpResponse(Object(Google_Http_Request), Object(Google_Client))
#1 /var/www/backend/phpsdk/examples/drive.php(95): Google_Http_MediaFileUpload->nextChunk('\xBA\x9AX\xBA\xAB\x9C
C\x91\x9E1\xDB|\xD0\xD5\xFB...')
#2 {main}
thrown in /var/www/backend/phpsdk/examples/apiClient/src/Google/Http/REST.php on line 110
Run Code Online (Sandbox Code Playgroud)
如果我再次执行该脚本,则会在 Drive 中创建一个新文件。
崩溃后如何恢复初始上传?我可以在初始化 Google_Http_MediaFileUpload 后设置 resumeUri 吗?如何让 PHP 跳过读取文件到特定点?
代码是从示例中复制/粘贴的:
// Create a media file upload to represent our upload process.
$media = new Google_Http_MediaFileUpload(
$client,
$request, …Run Code Online (Sandbox Code Playgroud) 鉴于我的服务器端点已收到与 Google In App Billing 购买相关的购买令牌,我该如何以编程方式对其进行验证并获得对其内容的访问权限?
我已经可以使用以下方法验证 Google登录令牌php
$client = new Google_Client(['client_id' => $client_id]);
$payload = $client->verifyIdToken($token);
if ($payload)
return $payload['sub'];
Run Code Online (Sandbox Code Playgroud)
但是我将如何使用Google_Client来验证购买令牌并访问其内容。
它真的只是GET像下面的 Ruby 示例一样将 a 发送到 Google 服务器的情况吗?
或者他们是Google_Client我应该调用的特定命令?
我开始认为这是在php使用中复制提到的 Ruby 代码OAuth2或其他东西的情况,因为 Google Docs 确实说一旦服务器拥有购买令牌:
使用 Google Play Developer API 的 Subscriptions 和 In-App Purchases 部分执行 GET 请求以从 Google Play 检索购买详细信息(Purchases.products 用于一次性产品购买或 Purchases.subscriptions 用于订阅)。GET 请求包括应用程序包名称、产品 ID 和令牌(购买令牌)。
如果可能的话只是想澄清一下?谢谢。
Google php API 库的规模非常大。我只想给图书馆发一封电子邮件。我怎样才能减小它的大小?
我正在尝试更新并从谷歌表格中获取一些结果,它正在运行但速度很慢。我需要batchUpdate并获取数据。
这是我的脚本
foreach ($import_cels as $celu => $valoare) {
$range_ins = $celu;
$valueRange->setValues(["values" => [$valoare]]);
$service->spreadsheets_values->update($spreadsheetId, $range_ins, $valueRange, $conf);
}
foreach ($cells_to_get as $celu => $valoare) {
$response = $service->spreadsheets_values->get($spreadsheetId, $celu);
$values = $response->getValues()[0][0];
echo "each cell :" . $values;
}
Run Code Online (Sandbox Code Playgroud)
问题:我有太多的请求,因为我一一更新单元格并提取相同的单元格。
我需要批量更新单元格并让它们像
B12 => 3
BB1 => 1
CC3 => 4
Run Code Online (Sandbox Code Playgroud) 使用适用于 PHP的Google API 客户端库,我正在尝试创建一个新的日历事件并附加一个hangoutsMeet会议。当我尝试这样做时,我收到一条错误消息,指出Invalid conference type value.
使用相同的代码,我能够创建一个新事件并附加一个eventHangout会议。
我明白为什么我会收到错误消息:根据 API,我的日历只支持eventHangout会议类型。
<<<< 2020 年 4 月 3 日编辑 #1
根据Andres Duarte的回答进行澄清:这仅在我尝试通过 API 创建事件时才显示为限制。当我手动创建使用谷歌日历界面的事件,我是能够添加谷歌见面。事实上,这是下拉列表中显示的唯一会议选项。
>>>>
我的问题是,如何更新我的日历设置(使用或不使用 API),以便我可以使用 API 来创建带有附加hangoutsMeet会议的活动?
这是一些示例代码来演示我尝试过的内容:
<<<< 2020 年 4 月 3 日编辑 #2
在hooman182的回答之后澄清:我已经更新了我的代码示例以证明我requestId使用字符串进行了正确设置。
>>>>
try {
// fetch the calendar
$calendar = 'myCalendar';
$calendarObject = $service->calendars->get($calendar);
echo "<pre>";
echo "\nORIGINAL *******************************************************\n\n";
var_dump($calendarObject->getConferenceProperties()->getAllowedConferenceSolutionTypes()); …Run Code Online (Sandbox Code Playgroud)