标签: google-api-php-client

Google Calendar API 添加事件回调以进行同步

google-api-php-client用于获取和插入 Google 日历事件。现在我想将系统上的事件与 Google 日历上的事件同步。

我想知道,如果我在 Google 日历中添加事件,它是否可以自动添加到我的系统中(可能带有一些回调 url),所以我不需要使用 CRON 作业在某个时间间隔内重新检查 Google 日历中的事件?

谢谢!

google-calendar-api google-api google-api-php-client

5
推荐指数
1
解决办法
1509
查看次数

用 PHP 创建简单的 Google 日历事件

我有一段时间试图使用 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)

php google-calendar-api google-api google-api-php-client

5
推荐指数
1
解决办法
4万
查看次数

如何使用 Google Calendar API v3/Google API 客户端库显示*所有*可用日历的列表?

我一直在尝试使用 PHP 访问 Google Calendar API v3。最初,我想简单地列出我可以通过 API 调用访问的用户日历。

为此,我下载了 Google API PHP 客户端库,并尝试使用以下代码(经过我的改编,来源自https://mytechscraps.wordpress.com/2014/05/15/accessing-google -calendar-using-the-php-api/):

<?php

//error_reporting(0);
//@ini_set('display_errors', 0);

// If you've used composer to include the library, remove the following line
// and make sure to follow the standard composer autoloading.
// https://getcomposer.org/doc/01-basic-usage.md#autoloading
require_once './google-api-php-client-master/autoload.php';

// Service Account info
$client_id = '754612121864-pmdfssdfakqiqblg6lt9a.apps.googleusercontent.com';
$service_account_name = '754674507864-pm1dsgdsgsdfsdfsdfdflg6lt9a@developer.gserviceaccount.com';
$key_file_location = 'Calendar-7dsfsdgsdfsda953d68dgdsgdsff88a.p12';


$client = new Google_Client();
$client->setApplicationName("Calendar");

$service = new Google_Service_Calendar($client);

$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
 $service_account_name,
 array('https://www.googleapis.com/auth/calendar.readonly'),
 $key …
Run Code Online (Sandbox Code Playgroud)

php google-calendar-api google-api google-client google-api-php-client

5
推荐指数
1
解决办法
9474
查看次数

如何在多个页面上使用 Google api?

我在多个页面上使用 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)

php google-api google-client google-api-php-client

5
推荐指数
1
解决办法
786
查看次数

如何彻底删除重复事件实例?

如果您在谷歌日历中创建重复事件,您实际上创建了一个具有重复规则的单个事件(父事件),其他事件只是虚拟添加。一旦您移动任何这些虚拟对象,它就会保存为实例,您可以按照您喜欢的任何方式对其进行编辑,而不会影响父事件本身。

如果您编辑该实例以匹配其父实例,它将被删除并再次替换为虚拟实例。(不需要保留与父事件没有什么不同的实例,对吗?)

我在我的应用程序中也做了同样的事情。但是,当我尝试使用 google-php-api-client 执行此操作时,删除某些内容的唯一选择是将事件状态设置为“已取消”,这将使实例被删除。

我的问题是:

如何删除(或重置)实例而不需要一一更新它们以匹配其父实例?

编辑:忘记提及为什么我需要这个以及我想要实现什么目标。

基本上,如果您编辑一个实例,Google 会询问您是否要编辑“仅此”“以下”“全部”重复事件。如果您选择“以下”,Google 将丢弃从此日期 ( where original_start > date) 起与父事件相关的所有内容,修改其规则以设置UNTIL正在编辑的实例日期的规则,并将其旧规则传递给新创建的事件,其开始时间与此特定实例的日期。

因为我不知道如何删除符合某些条件的多个事件。我能解决这个问题的唯一方法是选择所有这些,然后一一更新它们,这可能会有点问题,因为您可以:

  1. 创建未指定重复结束的重复事件
  2. 决定修改以下所有事件

google-calendar-api google-api-php-client

5
推荐指数
0
解决办法
4517
查看次数

Google Analytics API:为什么 API 数据与 Analytics 仪表板上看到的数据不同?

我已经研究这个有一段时间了,根据我收集的信息,它与抽样级别有关。

我从大多数其他 stackoverflow 问题中收集到的问题是,除非我有高级帐户,否则数据将始终按采样返回。

值得一问的是,有没有办法可以改变我的 Google API 查询,以便数据更准确一点?

我的查询代码:

$profiles = $analytics->management_profiles
    ->listManagementProfiles('myID', '~all');

foreach ($profiles->getItems() as $profile) {
    $IDvalue = $profile->getId();
    array_push($profilesArray, $IDvalue);
}

foreach ($profilesArray as $p) {
    $results = $analytics->data_ga->get(
        'ga:' . $p,
        '7daysAgo',
        'today',
        'ga:sessions');

    $profileName = $results->getProfileInfo()->getProfileName();
    $rows = $results->getRows();
    $sessions = $rows[0][0];

    print "Profile Name: $profileName";
    echo "<br>";
    print "Total Sessions: $sessions";
    echo "<br><br>";
}
Run Code Online (Sandbox Code Playgroud)

我尝试将我的更改get()为:

    $results = $analytics->data_ga->get(
        'ga:' . $p,
        '7daysAgo',
        'today',
        'ga:sessions',
        'samplingLevel:HIGHER_PRECISION');
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

    $results = $analytics->data_ga->get(
        'ga:' …
Run Code Online (Sandbox Code Playgroud)

php google-analytics google-api google-analytics-api google-api-php-client

5
推荐指数
1
解决办法
1877
查看次数

关于如何在服务器上验证 Google In App Purchase 购买令牌的说明?

鉴于我的服务器端点已收到与 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-api-php-client android-inapp-purchase

5
推荐指数
1
解决办法
3268
查看次数

如何减少 Google PHP 库的大小?

Google php API 库的规模非常大。我只想给图书馆发一封电子邮件。我怎样才能减小它的大小?

php google-api google-api-php-client

5
推荐指数
2
解决办法
380
查看次数

如何通过 Google Sheets 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)

batch-updates google-api-php-client google-sheets-api

5
推荐指数
1
解决办法
5360
查看次数

如何使用 Google Api v3 将 Google Sheets 以自定义格式导出为 PDF?

我正在使用Google Drive v3并尝试将 Google 电子表格文件导出为 PDF。几乎一切都按预期进行。

例外:

生成的 PDF 始终采用LETTERPORTRAIT格式,但我需要DIN A4横向格式的 pdf 。我无法找到任何设置/参数来提交到 v3 以生成其他格式的 PDF。

我找到了适用于 Google Drive v2 的解决方案,但没有找到适用于 Google Drive v3 的解决方案。

格式肖像作为可选参数传递会导致错误:-(

    /**
     * Downloads a Google file in a specified mime type.
     *
     * @param string   $googleDriveFileId id of the drive file which should be downloaded
     * @param string   $mimeType          mime type
     * @param string[] $optParams
     *
     * @return Response
     *
     * …
Run Code Online (Sandbox Code Playgroud)

php google-api google-drive-api google-api-php-client

5
推荐指数
1
解决办法
3102
查看次数