标签: google-api-php-client

Google日历API-邀请电子邮件在创建活动时不会发送给与会者

我想使用谷歌api将事件添加到谷歌日历.但在创建活动后,邀请电子邮件不会向与会者发送电子邮件列表.这是我的代码:

 <?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");

    // Visit https://code.google.com/apis/console?api=calendar to generate your
    // client id, client secret, and to register your redirect uri.
     $client->setClientId('309388785502.apps.googleusercontent.com');
     $client->setClientSecret('hvJQUDYz4rY0HiYcgS46yxB-');
     $client->setRedirectUri('http://localhost/GoogleApi/google-api-php-client/examples/calendar/simple.php');
     $client->setDeveloperKey('AIzaSyAbBRxRKM9mkXKA17Bruul6lCq-vhR6gqc');
    $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']);
    }

    if ($client->getAccessToken()) {

     $event = new Google_Event();
      $event->setSummary('Halloween3');
      $event->setLocation('The Neighbourhood');
      $start = new Google_EventDateTime();
      $start->setDate('2013-10-3'); …
Run Code Online (Sandbox Code Playgroud)

php google-api-php-client

2
推荐指数
1
解决办法
4408
查看次数

require_once(Google/Auth/AssertionCredentials.php):无法打开流:没有这样的文件或目录

我想做一个非常简单的事情:

require_once 'vendor/google/src/Google/Client.php';
require_once 'vendor/google/src/Google/Service/Plus.php';
Run Code Online (Sandbox Code Playgroud)

......我收到这个错误:

require_once(Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory
Run Code Online (Sandbox Code Playgroud)

为什么?

我正在使用https://github.com/google/google-api-php-client上提供的最新版本,似乎在Client.php中,每个require_once都使用错误的路径......或者不是?

任何帮助将不胜感激!

非常感谢,
Niccolò

google-api-php-client

2
推荐指数
1
解决办法
4228
查看次数

如何通过Google Oauth2和people.me对用户进行身份验证后获取电子邮件地址

我是php和google api的新手,当用户在使用Google+时,我正在尝试获取电子邮件地址,我使用$ plus-> people-> get("me")获取所有用户信息,但是我尝试通过此错误获取失败的电子邮件地址:

PHP注意:未定义的索引:值

这是我的代码:

<?php
session_start();

set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . "/src");

require_once 'Google/Client.php';

require_once 'Google/Service/Plus.php';

$client_id = 'XXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com';
$client_secret = 'XXXXXXXXXXXXXXXXXXX';
$redirect_uri = 'http://www.XXXXXXXXXXXXXX.com/pruebas.php';

$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/userinfo.profile");
$client->addScope("https://www.googleapis.com/auth/userinfo.email");

$plus = new Google_Service_Plus($client);

if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
}

if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']);
    $_SESSION['access_token'] = $client->getAccessToken();
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));

}

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
    $client->setAccessToken($_SESSION['access_token']);
    $_SESSION['token'] = $client->getAccessToken();

} else {
    $authUrl …
Run Code Online (Sandbox Code Playgroud)

php email google-plus google-api-php-client

2
推荐指数
1
解决办法
8587
查看次数

Google oAuth:redirect_uri_mismatch

尝试从Google获取oAuth令牌时,我们收到"redirect_uri_mismatch"错误:

[client 127.0.0.1:49892] {\n  "error" : "redirect_uri_mismatch"\n}, referer: `http://localhost/oAuth/chess-login.html`
Run Code Online (Sandbox Code Playgroud)

有两个文件正在使用:chess-login.html和plus.php(下面的代码).

Google API具有以下URI:

http://localhost/oAuth/chess-login.html
Run Code Online (Sandbox Code Playgroud)

有人能指出解决方案吗?

plus.php:

<?php

    $client_id = "XXX.apps.googleusercontent.com"; //your client id
    $client_secret = "XXX"; //your client secret
    $redirect_uri = "http://localhost/chess-login.html";
    $scope = "https://www.googleapis.com/auth/plus.login"; //google scope to access
    $state = "profile"; //optional
    $access_type = "offline"; //optional - allows for retrieval of refresh_token for offline access

    if(isset($_POST['results'])){
        $_SESSION['accessToken'] = get_oauth2_token($_POST['results']);
    }

    //returns session token for calls to API using oauth 2.0
    function get_oauth2_token($code) {
        global $client_id;
        global $client_secret;
        global $redirect_uri;

        $oauth2token_url …
Run Code Online (Sandbox Code Playgroud)

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

2
推荐指数
1
解决办法
5375
查看次数

未找到Google_DriveFile类Google Drive API

我在我的项目中使用google-api-php-client库.我正在使用Composer在我的项目中自动加载库.其他类(即:Google_Client)工作正常.当我去实例化一个对象时,根据Google文档,我收到以下错误:

Fatal error: Class 'Google_DriveFile' not found
Run Code Online (Sandbox Code Playgroud)

这是导致错误的行:

$file = new Google_DriveFile();
Run Code Online (Sandbox Code Playgroud)

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

2
推荐指数
1
解决办法
2000
查看次数

如何列出没有用户身份验证的Google日历活动

2014年11月17日,Google使用Zend Framework弃用了其Google Calendar API的v1和v2.

似乎在公开共享的Google日历上列出公开分享活动的唯一方法是使用OAuth 2.0通过GitHub中的新Google客户端库API

这意味着用于显示公共事件的公共网站的访问者现在必须进行身份验证和登录.

真的吗?没有其他方法可以继续展示公开的Google日历活动吗?

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

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

使用google api时如何设置refresh_token?

我正在尝试学习如何使用google api更改日历上的活动.服务器是将基于数据库中的信息更新日历的用户.实际上不需要用户交互.

问题是我在获取/使用刷新令牌时遇到问题.我单击添加到页面的"连接我"链接,它给我一个错误:

Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_request", "error_description" : "Missing required parameter: refresh_token" }

我已经尝试过这种方式设置刷新令牌,以及类似的方法,但它们似乎都不起作用,这让我觉得我正在错误地实现它们.

当我打印出$_SESSION['access_token']变量时,它显示没有refresh_token:

{"access_token":"token","token_type":"Bearer","expires_in":3599,"created":1417534503}

这是我用来授权没有refresh_token部分的'用户'的功能(基于一个例子):

function googleAuth(){

    $client_id = 'myclientid';
    $client_secret = 'myclientsecret';
    $redirect_uri = 'redirecturi';
    $client = new Google_Client();
    $client->setAccessType('offline');
    $client->setClientId($client_id);
    $client->setClientSecret($client_secret);
    $client->setRedirectUri($redirect_uri);
    $client->setScopes('https://www.googleapis.com/auth/calendar');

    /************************************************
    If we're logging out we just need to clear our
    local access token in this case
    ************************************************/
    if (isset($_REQUEST['logout'])) { …
Run Code Online (Sandbox Code Playgroud)

php google-api google-api-php-client

2
推荐指数
1
解决办法
5084
查看次数

PHP中当前Google API的BigQuery示例

所有关于示例的问题都是2年之久,我找不到当前API客户端版本的任何工作示例(https://github.com/google/google-api-php-client).每一个人都缺少一些东西或抛出异常....

有人可以提供工作实例吗?无论何时何地都没有文档.

这是最有效的一个:

<?php
    require_once 'inc/google-api/autoload.php'; // or wherever autoload.php is located

    $client = new Google_Client();
    $client->setApplicationName("whatever");
    $client->setDeveloperKey("some key");

    $service = new Google_Service_Bigquery($client);



    $postBody = "[
            'datasetReference' => [
                    'datasetId' => $datasetId,
                    'projectId' => $projectId,
            ],
            'friendlyName' => $name,
            'description' => $description,
            'access' => [
                    ['role' => 'READER', 'specialGroup' => 'projectReaders'],
                    ['role' => 'WRITER', 'specialGroup' => 'projectWriters'],
                    ['role' => 'OWNER', 'specialGroup' => 'projectOwners'],
            ],
    ]";

    $dataset = $service->datasets->insert($projectId, new Google_Dataset($postBody));

    $postBody = "[
            'tableReference' => [
                    'projectId' => …
Run Code Online (Sandbox Code Playgroud)

php google-bigquery google-api-php-client

2
推荐指数
1
解决办法
2651
查看次数

如何使用GuzzleHttp\Psr7\Response对象下载文件?

我正在尝试通过他们的api从谷歌存储中下载文件,当我通过alt = media参数时,我得到如下响应:

object(GuzzleHttp\Psr7\Response)#72 (6) {
  ["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=>
  string(2) "OK"
  ["statusCode":"GuzzleHttp\Psr7\Response":private]=>
  int(200)
  ["headers":"GuzzleHttp\Psr7\Response":private]=>
  array(16) {
    ["x-guploader-uploadid"]=>
    array(1) {
      [0]=>
      string(98) "AEnB2Uq5d_aKFnzd6d_DeJ_5P8vi9BiXOJpOzixs7mqU5_WK9SF0o9D-8vQiOQWLw"
    }
    ["content-type"]=>
    array(1) {
      [0]=>
      string(24) "application/octet-stream"
    }
    ["content-disposition"]=>
    array(1) {
      [0]=>
      string(10) "attachment"
    }
    ["etag"]=>
    array(1) {
      [0]=>
      string(16) "CODI1+sCEAE="
    }
    ["vary"]=>
    array(2) {
      [0]=>
      string(6) "Origin"
      [1]=>
      string(8) "X-Origin"
    }
    ["x-goog-generation"]=>
    array(1) {
      [0]=>
      string(16) "1458812108000"
    }
    ["x-goog-hash"]=>
    array(1) {
      [0]=>
      string(44) "crc32c=D0rU4U+yXOR8d0GKmxkDw=="
    }
    ["x-goog-metageneration"]=>
    array(1) {
      [0]=>
      string(1) "1"
    }
    ["cache-control"]=>
    array(1) {
      [0]=>
      string(46) "no-cache, no-store, …
Run Code Online (Sandbox Code Playgroud)

google-api google-cloud-storage google-api-php-client

2
推荐指数
1
解决办法
2255
查看次数

为什么我的Google Analytics(分析)API 4返回错误

您好,我正在使用PHP和Google Client API进行一个小项目。我不知道为什么会收到此错误消息:

消息:未定义的属性:Google_Service_Analytics :: $ reports

因为我的代码正确,所以与Google文档网页上的代码相同。

这是我的代码:

$client = new Google_Client();
    $client->setApplicationName("Hello Analytics Reporting");
    $client->setAuthConfig(FCPATH.'trim-tide-225210-c7xxxxssz7f4c.json');
    $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
    $analytics = new Google_Service_Analytics($client);
    $VIEW_ID = "ga:159882843";

      // Create the DateRange object.
      $dateRange = new Google_Service_AnalyticsReporting_DateRange();
      $dateRange->setStartDate("7daysAgo");
      $dateRange->setEndDate("today");

      // Create the Metrics object.
      $sessions = new Google_Service_AnalyticsReporting_Metric();
      $sessions->setExpression("ga:sessions");
      $sessions->setAlias("sessions");

      // Create the ReportRequest object.
      $request = new Google_Service_AnalyticsReporting_ReportRequest();
      $request->setViewId($VIEW_ID);
      $request->setDateRanges($dateRange);
      $request->setMetrics(array($sessions));

      $body = new Google_Service_AnalyticsReporting_GetReportsRequest();
      $body->setReportRequests( array( $request) );
      return $analytics->reports->batchGet( $body );
Run Code Online (Sandbox Code Playgroud)

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

2
推荐指数
1
解决办法
327
查看次数