我觉得这个会变得轻而易举.因此我一开始就陷入困境:-(
我创建了一个Google日历,用户可以使用"共享"专用登录信息添加活动.然后我需要在我的服务器上编写一个PHP脚本来读取给定时间范围内的事件.
我认为这里描述的API密钥就足够了.但事实并非如此.
curl https://www.googleapis.com/calendar/v3/users/me/calendarList?key=mykey
Run Code Online (Sandbox Code Playgroud)
说Login required.
所以我读到了OAuth2.0以及我需要用户进行身份验证的方法.问题是我的脚本不是交互式的(虽然硬编码脚本中的登录对我来说不是问题:信息不是生命关键).所以我读到了服务帐户,但它看起来像非用户信息.
问题:如何在不涉及人类的情况下编写脚本以强制执行给定登录?
注意:这个SO问题似乎很有希望,但答案是针对API版本2.0,这似乎已经过时了.
好吧,我一直试图获得Tim Bray的文章"从Android应用程序验证后端呼叫"所描述的精彩必杀技.我可以通过调用GoogleAuthUtil.getToken()从我的Android应用程序中成功获取令牌.我将令牌传递给我的php服务器作为头部授权承载字段.这是我被卡住的地方.
我现在该怎么做才能验证令牌是从我的Android应用程序生成的,用于与我的服务器项目相同的项目?如何从令牌获取user_id?谢谢.
在谷歌控制台上我的php服务器和Android应用程序都在同一个项目上.在我的php服务器上,我可以链接android/google-api-php-client/src/Google_Client.php和android/google-api-php-client/src/contrib/Google_PlusService.php库代码.
php android google-play-services google-oauth google-api-php-client
我正在尝试为Google日历创建一个活动,但我收到此错误:
Invalid value for: "T" found, can only parse bare date string: 2013-08-22T16:00:00
Run Code Online (Sandbox Code Playgroud)
我也尝试将时区偏移添加到我的字符串,但我在EventDateTime对象中手动设置时区,根据文档,它不是必需的.
以下是我创建时间字符串的方法:
data['start'] = $("#inputDateStart").val() + "T" + $("#inputTimeStart").val();
Run Code Online (Sandbox Code Playgroud)
以及如何在我的对象中设置此字符串
$start = new Google_EventDateTime();
$start->setTimeZone('America/Montreal');
$start->setDateTime($data['start']);
$event->setStart($start);
Run Code Online (Sandbox Code Playgroud)
我错过了什么?当我使用setDate函数设置日期时,全天活动正常.
按照有关如何插入webproperties的文档,以便我可以动态创建跟踪代码.目标是在Google Analytics中移动我们的分析,并在分析下自动在自己的Google帐户中创建客户网站.在我在网上找到的小东西之后,似乎这个功能可能被列入白名单.所以我正在提出这个问题来弄清楚天气是否如此.文档很难弄清楚,因为它没有告诉你需要哪些字段,字段意味着什么等.似乎文档已经过时的PHP库.不得不改变很多示例代码类名称和方法名称以使其"正常工作".
这是我用来测试此功能的代码片段.
<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
require_once 'Google/Service/Oauth2.php';
session_start();
$client = new Google_Client();
$client->setClientId('xxxxx');
$client->setClientSecret('xxxxxx');
$client->setRedirectUri('xxxxxxxx');
$client->setDeveloperKey('xxxxxxx');
$client->setScopes(
array(
'https://www.googleapis.com/auth/analytics.readonly',
'https://www.googleapis.com/auth/analytics',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/analytics.edit',
'https://www.googleapis.com/auth/analytics.manage.users'
)
);
$oauth2 = new Google_Service_Oauth2($client);
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($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
}
if (!$client->getAccessToken()) {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
} else {
$analytics = …Run Code Online (Sandbox Code Playgroud) php google-analytics google-api google-analytics-api google-api-php-client
我正在尝试使用最新的PHP客户端API(https://github.com/google/google-api-php-client)检索Google Analytics管理配置文件.
我有以下代码片段:
// we've got the token, so set it
$google_client->setAccessToken($_SESSION['access_code']);
if ($google_client->getAccessToken()) {
$profiles = $google_analytics_service->management_profiles->listManagementProfiles("~all", "~all");
print "<h1>Profiles</h1><pre>" . print_r($profiles, true) . "</pre>";
}
/* $url = 'https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/profiles'; */
/* // json decode as array */
/* $analytics_auth = json_decode($_SESSION['access_code'], true); */
/* $ch = curl_init($url . '?access_token=' . $analytics_auth['access_token']); */
/* curl_exec($ch); */
/* curl_close($ch); */
Run Code Online (Sandbox Code Playgroud)
我得到的错误信息是:
调用GET时出错https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/profiles?key=AIza[SNIP] :( 403)访问未配置
注意:但是我决定使用cURL运行相同的操作,并返回带有配置文件(注释代码)的JSON数组.这是一个错误,还是我?我注意到的是我的access_token以"ya29"开头.
php google-analytics google-api google-analytics-api google-api-php-client
我一直在尝试导入/包含我的PHP脚本文件中的文件,并以某种方式它无法正常工作.我知道这个require_once问题被多次询问[ 1. require_once with subfolders,2.require_once()无法找到包含路径,3.使用require_once for up directory not working ]但是它们似乎都不适用于我.
Blow图片将解释我想要做的事情:

我尝试了什么和错误:
require_once(__DIR__.'GoogleClientApi/src/Google/Service/Analytics.php');
echo 'Hey1'; //Does not echo this, means something went wrong above.
require_once(__DIR__.'GoogleClientApi/src/Google/Client.php');
echo 'Hey2';
Run Code Online (Sandbox Code Playgroud)

我得到的错误:

所以我决定使用绝对路径:
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php';
echo 'Hey1';
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Service/Analytics.php';
echo 'Hey2';
Run Code Online (Sandbox Code Playgroud)
给我Client.php文件中的错误:
`Warning: require_once(/Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php on line 18`
`Fatal error: require_once(): Failed opening required '/Google/Auth/AssertionCredentials.php' (include_path='.:/Applications/MAMP/bin/php/php5.5.10/lib/php') in /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php on line 18`
Investigating upon I found …Run Code Online (Sandbox Code Playgroud) php google-analytics require-once include-path google-api-php-client
我在使用Google Api Php Client和Google Fit时遇到问题。
我想获得一天中完成的所有步骤。
我找到了回应,但是没有用(请看要点)。
我的PHP代码:
// Retrive oauth data
$clientData = json_decode(file_get_contents("../Devbook-87e2bafd84e6.json"));
$client_email = $clientData->client_email;
$private_key = $clientData->private_key;
$scopes = array(Google_Service_Fitness::FITNESS_ACTIVITY_READ);
$credentials = new Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key
);
$client = new Google_Client();
$client->setState('offline');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); // Used in hybrid flows
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$fitness_service = new Google_Service_Fitness($client);
$dataSources = $fitness_service->users_dataSources;
$dataSets = $fitness_service->users_dataSources_datasets;
$listDataSources = $dataSources->listUsersDataSources("me");
$timezone = "GMT+0100";
$today = date("Y-m-d");
$endTime = …Run Code Online (Sandbox Code Playgroud) 我有一个脚本,它使用PHP Drive API中的可恢复上传原型,自从我实现它以来它已经工作了3到4个月.在星期六17,脚本停止工作,由于出现此问题,crontab没有运行脚本:
[17-Oct-2015 05:15:07 America/Chicago] PHP Fatal error: Uncaught exception 'Google_IO_Exception' with message 'HTTP Error: Unable to connect: 'fopen(): SSL: Broken pipe'' in /root/scriptEnCrontab/libs/src/Google/IO/Stream.php:141
Stack trace:
#0 /root/scriptEnCrontab/libs/src/Google/IO/Abstract.php(136): Google_IO_Stream->executeRequest(Object(Google_Http_Request))
#1 /root/scriptEnCrontab/libs/src/Google/Http/MediaFileUpload.php(164): Google_IO_Abstract->makeRequest(Object(Google_Http_Request))
#2 /root/scriptEnCrontab/respaldoDrive_cgi.php(183): Google_Http_MediaFileUpload->nextChunk('\x8EGu\xA9Y\xE9\xEEQ\x9B\xE1\xAD\x98Xw\xEB...')
#3 /root/scriptEnCrontab/respaldoDrive_cgi.php(96): insertFile(Object(Google_Client), Object(Google_Service_Drive), '/root/respaldo/...', 'RespaldoScripts...', '0B2Xiur2QhdC6fk...')
#4 {main}
thrown in /root/scriptEnCrontab/libs/src/Google/IO/Stream.php on line 141
Run Code Online (Sandbox Code Playgroud)
经过一些调整,升级和安装cURL后,问题就变为了
[20-Oct-2015 18:57:21 America/Chicago] PHP Fatal error: Uncaught exception 'Google_IO_Exception' with message 'Couldn't resolve host 'www.googleapis.com'' in /root/scriptEnCrontab/libs/src/Google/IO/Curl.php:115
Stack trace:
#0 /root/scriptEnCrontab/libs/src/Google/IO/Abstract.php(136): Google_IO_Curl->executeRequest(Object(Google_Http_Request))
#1 /root/scriptEnCrontab/libs/src/Google/Http/MediaFileUpload.php(164): Google_IO_Abstract->makeRequest(Object(Google_Http_Request))
#2 /root/scriptEnCrontab/respaldoDrive_cgi.php(186): Google_Http_MediaFileUpload->nextChunk('C\x9D\t\xD9\x95\x1F\xAF\xF5!qJ\xCAq\x8CB...') …Run Code Online (Sandbox Code Playgroud) 我们正在使用混合身份验证流程,以便通过JS请求客户端进行增量授权,并将结果code传递给我们的API服务器进行处理.
我们需要的是:
通过刷新令牌或访问令牌,用户可以使用哪些范围
一种在$client->authenticate($code)响应中包含当前作用域的方法(因此我们可以使用刷新令牌存储它们)
一种确定Google响应中授予的范围的方法$client->authenticate($code)(因此我们可以将其附加到该用户的存储列表中)
我们希望在集成页面上显示一个列表,供用户选择加入每个功能(日历,联系人,驱动器)并显示已启用哪些功能的清晰列表,以及提示他们是否访问尚未授权的功能特征.除此之外,我无法相信这不是"一件事".
我正在尝试使用Google API 2.0.0 RC4 for PHP从我自己的收件箱(作为项目所有者)获取给定的电子邮件.
我有一个项目设置,一个JSON格式的下载认证文件,我在Google Developers Console中启用了gmail API.
但是,当我运行以下代码时,出现"错误请求"错误,原因是"failedPrecondition".现在这让我相信访问权限存在问题,但我无法弄清楚我需要做什么.
码:
<?php
require_once("google-api-php-client-2.0.0-RC4/vendor/autoload.php");
$client = new Google_Client();
// set the scope(s) that will be used
$client->setScopes(["https://www.googleapis.com/auth/gmail.readonly"]);
$client->setApplicationName("MyProject");
// set the authorization configuration using the 2.0 style
$client->setAuthConfigFile("myAuthFile.json");
$gmailHandle = new Google_Service_Gmail($client);
$messages = $gmailHandle->users_messages->get("myemail@mydomain.com", "12343445asd56");
echo json_encode($messages);
?>
Run Code Online (Sandbox Code Playgroud)
完整的错误看起来像这样:
致命错误:未捕获的异常'Google_Service_Exception',消息'{"错误":{"errors":[{"domain":"global","reason":"failedPrecondition","message":"Bad Request"}], "code":400,"message":"Bad Request"}}'
php ×8
google-api ×5
android ×1
curl ×1
gmail ×1
gmail-api ×1
google-fit ×1
google-oauth ×1
include-path ×1
require-once ×1