标签: google-api-php-client

Google Drive API - PHP客户端库 - 将uploadType设置为可恢复上传

我对新的Google Drive API客户端库的文档存在严重问题.看起来这应该是一个容易回答,而不必把它放在stackoverflow上.我正在认真考虑在这一个上推广我自己,一个64页的图书馆,"正常工作"到目前为止是"令人头疼"

如何将uploadType设置为"可恢复"而不是默认的"简单".我在图书馆搜索了一种方法,但它似乎不存在.他们唯一的提示是他们的示例上传页面上的代码https://developers.google.com/drive/quickstart-php

//Insert a file
$file = new Google_DriveFile();
$file->setTitle('My document');
$file->setDescription('A test document');
$file->setMimeType('text/plain');

$data = file_get_contents('document.txt');

$createdFile = $service->files->insert($file, array(
      'data' => $data,
      'mimeType' => 'text/plain',
    ));
Run Code Online (Sandbox Code Playgroud)

这里没有设置uploadType ... ???

他们在另一个页面上的文档只是将uploadType作为地址的一部分显示为GET:https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable但是当您使用时$service->files->insert,库会设置地址.

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

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

如何在不使用谷歌应用程序的情况下授权谷歌硬盘服务帐户访问谷歌帐户?

我想使用Google云端硬盘作为我正在制作的网站的准CMS,以便内容所有者可以使用Google云端硬盘修改其内容.我想使用可以访问Google云端硬盘的特定用户帐户(撰写此帖子时,服务帐户无法直接访问Google云端硬盘),并且能够与内容所有者共享文档.

阅读完API和教程后,我在代表团中找到了答案:https://developers.google.com/drive/delegation

我在此过程中遇到的主要问题是该网站不受Google Apps管理,因此"将您的服务帐户的域名授权权限委托"中列出的步骤让我感到困惑 - 似乎应该可以在不使用Google的情况下处理此授权应用,但在搜索了我的特定用户帐户的Google云端硬盘设置后,我似乎无法找到授权模拟的功能.

我正在使用的代码片段:

static public function getService() {
  $key = file_get_contents(GOOGLEAPI_KEYFILE);
  $auth = new Google_AssertionCredentials(GOOGLEAPI_SERVICE_EMAIL, array(GOOGLEAPI_SCOPE), $key);
  $auth->setPrn(GOOGLEAPI_IMPERSONATION);
  self::$apiClient = new Google_Client();
  self::$apiClient->setUseObjects(true);
  self::$apiClient->setAssertionCredentials($auth);
  return new Google_DriveService(self::$apiClient);
}
Run Code Online (Sandbox Code Playgroud)

GOOGLEAPI_IMPERSONATION 是特定的用户帐户,当我运行此代码时,异常指出:

刷新OAuth2令牌时出错,消息:'{"error":"access_denied"}

有人提供任何帮助吗?我是否误解了oAuth如何在授权方面发挥作用的基本概念?

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

7
推荐指数
1
解决办法
3889
查看次数

在网络应用程序中嵌入Google+环聊应用

有没有办法在基于PHP的网站中嵌入Google+环聊应用?我可以在iframe中加载应用,而无需登陆Google+环聊页面吗?如果是这样,怎么样?

google-api google-plus hangout google-api-php-client

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

在laravel中为Google日历添加Google php API

我想使用Google php api访问日历.我正在和laravel一起工作.我已经在作曲家上添加了这个包并且下载得很好,这就是我与提供者和别名或者用我的应用程序链接api的任何事情.我想调用Calendar类.我正确地使用另一个库,artdarek/oauth-4-laravel,我可以用这个api显示日历,但我不能插入/编辑日历,这是一个更简单的方法吗?

提供者:

'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    'Illuminate\Cache\CacheServiceProvider',
    'Illuminate\Session\CommandsServiceProvider',
    'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
    'Illuminate\Routing\ControllerServiceProvider',
    'Illuminate\Cookie\CookieServiceProvider',
    'Illuminate\Database\DatabaseServiceProvider',
    'Illuminate\Encryption\EncryptionServiceProvider',
    'Illuminate\Filesystem\FilesystemServiceProvider',
    'Illuminate\Hashing\HashServiceProvider',
    'Illuminate\Html\HtmlServiceProvider',
    'Illuminate\Log\LogServiceProvider',
    'Illuminate\Mail\MailServiceProvider',
    'Illuminate\Database\MigrationServiceProvider',
    'Illuminate\Pagination\PaginationServiceProvider',
    'Illuminate\Queue\QueueServiceProvider',
    'Illuminate\Redis\RedisServiceProvider',
    'Illuminate\Remote\RemoteServiceProvider',
    'Illuminate\Auth\Reminders\ReminderServiceProvider',
    'Illuminate\Database\SeedServiceProvider',
    'Illuminate\Session\SessionServiceProvider',
    'Illuminate\Translation\TranslationServiceProvider',
    'Illuminate\Validation\ValidationServiceProvider',
    'Illuminate\View\ViewServiceProvider',
    'Illuminate\Workbench\WorkbenchServiceProvider',
    'Artdarek\OAuth\OAuthServiceProvider',
    'Google\Client',
),
Run Code Online (Sandbox Code Playgroud)

这是别名:

'aliases' => array(

    'App'             => 'Illuminate\Support\Facades\App',
    'Artisan'         => 'Illuminate\Support\Facades\Artisan',
    'Auth'            => 'Illuminate\Support\Facades\Auth',
    'Blade'           => 'Illuminate\Support\Facades\Blade',
    'Cache'           => 'Illuminate\Support\Facades\Cache',
    'ClassLoader'     => 'Illuminate\Support\ClassLoader',
    'Config'          => 'Illuminate\Support\Facades\Config',
    'Controller'      => 'Illuminate\Routing\Controller',
    'Cookie'          => 'Illuminate\Support\Facades\Cookie',
    'Crypt'           => 'Illuminate\Support\Facades\Crypt',
    'DB'              => 'Illuminate\Support\Facades\DB',
    'Eloquent'        => 'Illuminate\Database\Eloquent\Model',
    'Event'           => 'Illuminate\Support\Facades\Event',
    'File' …
Run Code Online (Sandbox Code Playgroud)

php google-calendar-api laravel google-api-php-client laravel-4

7
推荐指数
1
解决办法
6808
查看次数

通过Google Calendar API发送活动的电子邮件通知

我正在使用calendar.events.insert API通过PHP客户端向我的日历添加一个事件.正确插入事件以及API设置的适当值.然而,相同的情况是无法向与会者触发电子邮件邀请.我环顾四周发现请求需要将param sendNotifications设置为true.这似乎也没有帮助.

这是一个示例代码:

var request = gapi.client.calendar.events.insert({
        "calendarId" : calendarData.id,
        "sendNotifications": true,
        "end": {
          "dateTime": eventData.endTime
        },
        "start": {
          "dateTime": eventData.startTime
        },
        "summary": eventData.eventName, 
        "attendees": jQuery.map(eventData.attendees, function(a) {
          return {'email' : a};
        }),
        "reminders": {
          "useDefault": false,
          "overrides": [
            {
              "method": "email",
              "minutes": 15
            },
            {
              "method": "popup",
              "minutes": 15
            }
          ]
       }
      });
Run Code Online (Sandbox Code Playgroud)

其中eventData和calendarData是适当的对象.

虽然我的主要问题是第一次发送电子邮件邀请,但我也尝试(如上所示)设置提醒(使用覆盖).虽然弹出窗口按预期工作,但在这种情况下我也没有收到电子邮件更新.

这让我想知道这是否是一个权限问题 - 我需要为我的应用程序启用(用户可以理解我的应用程序是否代表他们发送电子邮件)?

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

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

在Google API v2中,为什么会出现错误"用于调用Google Play Developer API的项目ID尚未链接"?

当我使用Google API v2时,为了获得一个inapp列表,我在进行API调用时遇到以下错误:

{
 "error": {
  "errors": [
   {
    "domain": "androidpublisher",
    "reason": "projectNotLinked",
    "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
   }
  ],
  "code": 403,
  "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
 }
}
Run Code Online (Sandbox Code Playgroud)

然后我研究了这个错误,最后看到了这个页面,这个页面以及这个页面上的建议.我跟着并仔细检查了项目在那里的链接方式,但没有帮助.

这就是我做的......

在Google Developer Console中:

  1. 使用现有项目.
  2. 去了API&auth> API.
  3. 确保"Google …

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

7
推荐指数
1
解决办法
7404
查看次数

刷新OAuth2令牌时出错,消息:'{"error":"unauthorized_client","error_description":"请求中未经授权的客户端或范围".}"

当我尝试从Google Analytics获取数据时,我收到了错误消息

刷新OAuth2令牌时出错,消息:'{"error":"unauthorized_client","error_description":"请求中未经授权的客户端或范围".}"

我在https://console.developers.google.com/project中创建项目,创建 服务帐户并下载.p12密钥.同时在项目设置中启用"Analytics API",但它不起作用.这是我的代码:

    $service_account_name = '<Service Email>@developer.gserviceaccount.com';
    $key_file_location = '<keyName>.p12';
    $key = file_get_contents($key_file_location);
    $cred = new Google_Auth_AssertionCredentials(
        $service_account_name,
        array(Google_Service_Analytics::ANALYTICS),
        $key,
        'notasecret',
        'http://oauth.net/grant_type/jwt/1.0/bearer',
        '<My email>'
    );
$client->getAuth()->setAssertionCredentials($cred);
$service = new Google_Service_Analytics($client);
$result = $service->data_ga->get("ga:<profileID>", "yesterday", "today", "ga:pageviews");
print_r( $result);
Run Code Online (Sandbox Code Playgroud)

我的项目有什么问题?请帮忙.

php google-analytics-api oauth-2.0 google-oauth google-api-php-client

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

令牌中的段数错误(OAuth Google Api with php)

我有一个 php 应用程序,它使用 OAuth2 对用户的帐户进行身份验证。

直到昨天,一切都进展顺利。

但是今天,在不更改代码的情况下,当我尝试访问我的帐户时,并且在对我的谷歌帐户进行身份验证后,我获得了一个空白页面。

我调试代码,发现当 Google_Client 尝试 verifyIdToken 时崩溃,更准确地说是在函数 verifySignedJwtWithCerts 中,因为:$segments = explode(".", $jwt);找到 4 个段而不是 3 个段。

这是我的代码:

...
$client = new Google_Client();
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setRedirectUri($redirectUri);
$client->setScopes("email");

if(!isset($_GET['code']))
    header("Location: ".$client->createAuthUrl());
else
{
    $client->authenticate($_GET['code']);
    $_SESSION["access_token"] = $client->getAccessToken();


    if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
      $client->setAccessToken($_SESSION['access_token']);
    } else {
      $authUrl = $client->createAuthUrl();
    }

    $ticket = $client->verifyIdToken();
    if ($ticket) {
        $admin = $ticket->getAttributes();

    }
    $_SESSION["email"] = $admin["payload"]["email"];

    ...
Run Code Online (Sandbox Code Playgroud)

谁能提供解释吗?提前致谢

php google-oauth google-api-php-client

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

Google API服务帐户授权错误

我使用google-api-php-client客户端使用服务帐户连接到Google云端硬盘.它大部分时间都有效,但每隔一段时间(例如,如果我坐在这里每隔5到10次刷一遍页面),我会收到一条Google_Service_Exception消息unauthorized_client: Client is unauthorized to retrieve access tokens using this method.只有$this->drive_service->files->listFiles()代码存在时才会出现错误.如果我直接使用服务帐户而不是setSubject()模仿其他用户,则不会发生这种情况.

        $this->client = new Google_Client();
        $this->client->useApplicationDefaultCredentials();
        $this->client->addScope("https://www.googleapis.com/auth/drive");
        $this->client->setSubject('xxxx');
        $this->drive_service = new Google_Service_Drive($this->client);
        $files = $this->drive_service->files->listFiles();
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

2017年2月21日更新:错误不再是间歇性的,每次都会发生错误,因此我无法再通过服务帐户连接到常规帐户.

2017年3月10日更新:好像这是用户的误解.必须为服务帐户授予"域范围权限"才能冒充该域的用户 - 这是我尚未做过的事情.我只是授权客户端访问此处所述的用户帐户.

google-api google-api-php-client service-accounts

7
推荐指数
1
解决办法
3194
查看次数

需要同意才能将文件的所有权转让给其他用户 [Google Drive API]

我有一个与 1 个用户 - 所有者(Gmail 帐户)和第二个用户 - 作者(Google 服务帐户,如 @iam.gserviceaccount.com)共享的 Google 表格文件。

我使用此函数由用户 2 从用户 1 复制表,并再次使复制文件的所有者为用户 1:

$ownerPermission = new Google_Service_Drive_Permission([
'type'         => 'user', 
'role'         => 'owner',
'emailAddress' => 'user1@gmail.com'
]);
$requestOwnership = $service->permissions->create($newfileId, $ownerPermission, ['fields' => 'id', 'transferOwnership' => 'true']); 
Run Code Online (Sandbox Code Playgroud)

直到昨天一切都运转良好!现在,Google Drive API 返回错误:需要同意才能将文件的所有权转让给其他用户

如何修复它?

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

7
推荐指数
1
解决办法
2555
查看次数