我只是使用PHP api的实际版本的示例,并使用examples文件夹的"service-account.php"文件.
原始版本用于显示"Books API",并且使用我的个人凭据配置它运行良好,但在我的xcase中,我需要通过directory.groups.get服务访问以获取Google群组邮件列表的成员帐户列表,所以我改变了原来的代码:
<?php
session_start();
include_once "templates/base.php";
/************************************************
Make an API request authenticated with a service
account.
************************************************/
require_once realpath(dirname(__FILE__) . '/../autoload.php');
/************************************************
************************************************/
// MY ACCOUNT DATA HERE
$client_id = 'xxx';
$service_account_name = 'xxx'; //Email Address
$key_file_location = 'xxx.p12'; //key.p12
$groupKey = 'xxx';
echo pageHeader("My Service Account Access");
if ($client_id == '<YOUR_CLIENT_ID>'
|| !strlen($service_account_name)
|| !strlen($key_file_location)) {
echo missingServiceAccountDetailsWarning();
}
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
//$service = new Google_Service_Books($client); //ORIGINAL
$service = new Google_Service_Directory($client);
/************************************************
************************************************/
if (isset($_SESSION['service_token'])) …Run Code Online (Sandbox Code Playgroud) 我正在使用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
我正在将我的网站登录系统从LightOpenID更新为Google的Oauth 2.0.
当我需要Client.php和Service/Oauth2.php时,我收到错误
致命错误:第32行/home/myname/repos/website_current/lib/google-api-php-client/src/Google/Service/Oauth2.php中未找到"Google_Service"类
我正在使用的代码(来自我的login.php文件)看起来像这样
require_once(dirname($_SERVER['DOCUMENT_ROOT']).'/lib/autoload.php');
require('Google/Client.php');
require('Google/Service/Oauth2.php');
echo "exit";
exit();
Run Code Online (Sandbox Code Playgroud)
我在PHP.ini中添加了include路径(在/etc/php5/apache2/php.ini中)
include_path = ".:/usr/local/lib/php:/home/myname/repos/website_current/lib/google-api-php-client/src"
Run Code Online (Sandbox Code Playgroud)
所以它似乎我的Oauth2.php文件看不到任何其他包括类'Google_Service',这是'Service.php'中的一个文件夹.
我的文件夹结构如下所示:
lib/
... autoload.php
... functions.php
... google-api-php-client/
... src/
... Google/ (etc etc)
public_html/
... login/
...login.php
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会这样.应该看到包含路径,并使用phpinfo()显示为包含的路径; 有人可以给我一些见解吗?
我正在使用Yii2,GoogleOAuth和yii2用户扩展.我想接收用户谷歌圈子并将范围设置为我的配置:
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\clients\GoogleOAuth',
'clientId' => '758709912345-p4qp4lqihit5un1u6qb75msqp5m5j6d8.apps.googleusercontent.com',
'clientSecret' => 'ZygOIi1-0asfktUQ1pKOFOo',
'scope' => 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/drive',
],
],
]
Run Code Online (Sandbox Code Playgroud)
当我使用Google OAuth2登录时出现错误:
异常 - yii\authclient\InvalidResponseException请求失败,代码:400,消息:{"error":"redirect_uri_mismatch"}
谷歌回应:
[
'url' => 'https://accounts.google.com/o/oauth2/token'
'content_type' => 'application/json'
'http_code' => 400
'header_size' => 435
'request_size' => 644
'filetime' => -1
'ssl_verify_result' => 0
'redirect_count' => 0
'total_time' => 0.115431
'namelookup_time' => 0.001186
'connect_time' => 0.025188
'pretransfer_time' => 0.076275
'size_upload' => 456
'size_download' => 39
'speed_download' …Run Code Online (Sandbox Code Playgroud) 我正在使用google-api-php-client 0.6.1而且我想知道有没有办法冒充具体用户的服务帐号?我的应用程序需要在其谷歌硬盘中存储一些文件.所以,我决定使用服务帐户和.p12密钥 - 验证.它运行良好,但所有文件都存储在服务帐户中,因此我无法管理它们.我希望将文档存储在特定帐户(用于创建api项目和服务帐户本身).我试图使用这段代码:
$KEY_FILE = <p12 key file path>;
$key = file_get_contents($KEY_FILE);
$auth = new Google_AssertionCredentials(
$SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/drive'),
$key);
$auth->prn = '<certainuser@gmail.com>';
$client = new Google_Client();
$client->setUseObjects(true);
$client->setAssertionCredentials($auth);
return new Google_DriveService($client);
Run Code Online (Sandbox Code Playgroud)
但是我收到了"刷新OAuth2令牌时出错,消息:'{"error":"access_denied"}'"
我收到以下错误:
OAuth 2.0访问令牌已过期,并且刷新令牌不可用.对于自动批准的响应,不会返回刷新令牌
我有一个只有我的服务器才能访问的Web应用程序,初始身份验证工作正常,但一小时后,弹出上述错误消息.我的脚本看起来像这样:
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey("{MY_API_KEY}");
$client->setClientId('{MY_CLIENT_ID}.apps.googleusercontent.com');
$client->setClientSecret('{MY_KEY}');
$client->setRedirectUri('{MY_REDIRECT_URI}');
$client->setScopes(array('https://www.googleapis.com/auth/gmail.readonly'));
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (!$client->getAccessToken() && !isset($_SESSION['token'])) {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
Run Code Online (Sandbox Code Playgroud)
如何为此设置刷新令牌?
编辑1:我也尝试过使用服务帐户.我按照GitHub上提供的文档:
https://github.com/google/google-api-php-client/blob/master/examples/service-account.php
我的脚本看起来像这样:
session_start();
include_once "templates/base.php";
require_once 'Google/Client.php';
require_once 'Google/Service/Gmail.php';
$client_id = '{MY_CLIENT_ID}.apps.googleusercontent.com';
$service_account_name = '{MY_EMAIL_ADDRESS}@developer.gserviceaccount.com ';
$key_file_location = 'Google/{MY_KEY_FILE}.p12';
echo pageHeader("Service Account Access");
if …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过此处的说明实现Google的登录API ,但出于某种原因,当我尝试运行它时,我总是得到:
致命错误:第76行/home/.../Google/Client.php中未找到"Google_Config"类
我很确定我正确链接到Client.php - 我不认为这是我自己的代码中的问题.有谁知道这里会发生什么?谢谢!
我已经编写了一个用于较大文件的文件上传,即将文件上传到云存储。不幸的是,这需要一段时间,因为文件首先上传到网络服务器,然后再次从网络服务器上传到 Google 云存储。有没有办法使用 Google PHP Api 客户端(https://github.com/google/google-api-php-client)将文件直接上传到云存储?我在文档中找不到有关此主题的任何内容。
我们将YouTube Live Streaming API与Google API PHP客户端结合使用,我无法弄清楚如何使用基本(预设)提取而不是自定义提取.
自定义的是正常的,但由于某些原因,即使您将它们称为相同的名称,它也会为您创建的每个流不断创建重复项.
所以我的问题是,我们如何让它使用基本的摄取或者能够选择一个自定义的,而不是每次都创建一个新的?
例如,您可以在YouTube帐户中手动设置流时选择基本提取:
相关的PHP代码:
// Create an object for the liveBroadcast resource's snippet. Specify values
// for the snippet's title, scheduled start time, and scheduled end time.
$broadcastSnippet = new Google_Service_YouTube_LiveBroadcastSnippet();
$broadcastSnippet->setTitle($this->title);
$broadcastSnippet->setDescription($this->desc);
$broadcastSnippet->setScheduledStartTime($this->start_time);
// Create an object for the liveBroadcast resource's status, and set the
// broadcast's status.
$status = new Google_Service_YouTube_LiveBroadcastStatus();
$status->setPrivacyStatus($this->privacy_status);
// Create the API request that inserts the liveBroadcast resource.
$broadcastInsert = new Google_Service_YouTube_LiveBroadcast();
$broadcastInsert->setSnippet($broadcastSnippet);
$broadcastInsert->setStatus($status); …Run Code Online (Sandbox Code Playgroud) youtube youtube-api google-api-php-client youtube-data-api youtube-livestreaming-api
我即将开始使用Google 的日历 API,我要求访问我的用户的日历。在php 文档示例中,令牌存储在文件(token.json)中,但在我的情况下,每个用户都可以有一个访问令牌,所以我想将其存储在用户的数据库表中。
php ×8
google-oauth ×3
oauth-2.0 ×2
access-token ×1
api ×1
gmail ×1
google-api ×1
google-plus ×1
javascript ×1
oauth ×1
yii2 ×1
yii2-user ×1
youtube ×1
youtube-api ×1