我想知道如何使用PHP与Google电子表格进行互动.
我查看了Google的许多文档,但是,这些都不是我正在寻找的.
我的目标是能够使用oAuth(而不是电子邮件/通行证)更改单元格的内容.
如果这是一个RTFM问题,请原谅我,但我确实花了超过2周的时间没有结果.:/
我的要求出了什么问题?
我有俄语刺痛:
$string = ?????????, %
我想用Google API将其翻译成乌克兰语:
我urlencode字符串:
$q = urlencode($string)
Run Code Online (Sandbox Code Playgroud)
我要求谷歌API:
作为回应,我得到:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Value"
}
],
"code": 400,
"message": "Invalid Value"
}
}
Run Code Online (Sandbox Code Playgroud)
我的要求出了什么问题?
我正在关注https://developers.google.com/gmail/api/guides/push 上给出的 Gmail API 推送通知指南。但是,当我尝试从 API 资源管理器创建新手表时,它给出了以下响应:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid topicName does not match projects/google.com:apisexplorerconsole/topics/*"
}
],
"code": 400,
"message": "Invalid topicName does not match projects/google.com:apisexplorerconsole/topics/*"
}
Run Code Online (Sandbox Code Playgroud)
}
我的要求如下:
POST https://www.googleapis.com/gmail/v1/users/myemailaddress/watch?key={YOUR_API_KEY}
{
"labelIds": [
"INBOX"
],
"topicName": "projects/my-project-name/topics/my-topic-name"
}
Run Code Online (Sandbox Code Playgroud)
似乎在 Google API 端进行了错误的验证检查。还有其他人面临这个问题吗?
我已经创建了一个具有Google OAuth2凭据的项目,可用于Google日历。
但是访问令牌每隔1小时就会过期。
有人可以帮我将过期时间更改为1天。
我已使用此代码访问Google日历事件:
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setAccessType('offline');
$client->setScopes(array('https://www.googleapis.com/auth/calendar'));
if (isset($_GET['code']))
$google_oauth_code = $_GET['code'];
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$_SESSION['last_action'] = time();
}
Run Code Online (Sandbox Code Playgroud) php google-calendar-api google-api google-oauth google-api-php-client
以下代码应该能够按 EXACT eventCategory 进行过滤,但它不起作用。它返回所有可用的事件,当然它有点混乱。
/*
this querystring is what I'd like to receive, I've built it with the query explorer: https://ga-dev-tools.appspot.com/query-explorer/
ids=ga:private&
start-date=2017-05-01&
end-date=yesterday&
metrics=ga:eventValue,ga:avgEventValue&
dimensions=ga:subContinent,ga:eventCategory,ga:eventAction,ga:eventLabel&
filters=ga:eventCategory==video
*/
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("3daysago");
$dateRange->setEndDate("today");
// Create the Metrics object.
$ev = new Google_Service_AnalyticsReporting_Metric();
$ev->setExpression("ga:eventValue");
$ev->setAlias("EventValue");
$avg = new Google_Service_AnalyticsReporting_Metric();
$avg->setExpression("ga:avgEventValue");
$avg->setAlias("Avg Value");
//Create the dimensions
$sc = new Google_Service_AnalyticsReporting_Dimension();
$sc->setName("ga:subContinent");
$ec = new Google_Service_AnalyticsReporting_Dimension();
$ec->setName("ga:eventCategory");
$ea = new Google_Service_AnalyticsReporting_Dimension();
$ea->setName("ga:eventAction");
$el = new Google_Service_AnalyticsReporting_Dimension();
$el->setName("ga:eventLabel"); …Run Code Online (Sandbox Code Playgroud) 我正在关注下面的文章, https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/web-php
但是最后,当我尝试使用示例代码(HelloAnalytics.php)时,它会在命令行中显示如下错误并且无法获取数据;
PHP 警告:count(): Parameter must be an array or an object that implementation Countable in C:\xampp\htdocs\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67
警告:count(): Parameter must be an array or an object that implementation Countable in C:\xampp\htdocs\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67 PHP Warning: count(): Parameter must是第 67 行 C:\xampp\htdocs\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php 中实现 Countable 的数组或对象
警告:count():参数必须是在 C:\xampp\htdocs\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php 中实现 Countable 的数组或对象,第 67 行 PHP 致命错误:未捕获的 Google_Service_Exception:{" error":{"errors":[{"domain":"usageLimits","reason":"accessNotConfigured","message":"Project 687417168367 未找到且不能用于 API 调用。如果它是最近创建的,通过访问https://console.developers.google.com/apis/api/analytics.googleapis.com/overview?project=687417168367启用 Google Analytics API,然后重试。如果您最近启用了此 API,请等待几分钟以进行操作传播到我们的系统并重试。","extendedHelp":" https://console.developers.google。com/apis/api/analytics.googleapis.com/overview?project=687417168367"}],"code":403,"message":"项目 687417168367 未找到,无法用于 API 调用。如果它是最近创建的,请访问https://console.developers.google.com/apis/api/analytics.googleapis.com/overview?project=687417168367启用 Google Analytics …
我按照这些教程在 PHP 中使用 Firestore:https : //github.com/googleapis/google-cloud-php-firestore https://firebase.google.com/docs/firestore/quickstart
但是当我加载我的页面时,会显示此消息:
Google\ApiCore\ValidationException:呈现“projects/{project= }/databases/{database= }”时出错:预期绑定“project”以匹配段“{project=*}”,而是得到空提供的绑定:数组([project ] => [database] => (default) ) 在 C:\wamp64\www\php\vendor\google\gax\src\ResourceTemplate\RelativeResourceTemplate.php 第 238 行'
这是我的代码:
作曲家.json:
{
"require": {
"google/cloud-firestore": "^1.4",
"grpc/grpc": "v1.19.0"
}
}
Run Code Online (Sandbox Code Playgroud)
index.php(示例的副本):
require ('vendor/autoload.php');
use Google\Cloud\Firestore\FirestoreClient;
/**
* Initialize Cloud Firestore with default project ID.
* ```
* initialize();
* ```
*/
// Create the Cloud Firestore client
$db = new FirestoreClient();
printf('Created Cloud Firestore client with default project ID.' .
PHP_EOL);
$docRef = $db->collection('users')->document('lovelace');
$docRef->set([
'first' …Run Code Online (Sandbox Code Playgroud) php firebase google-api-php-client grpc google-cloud-firestore
我一直在使用PHP OAuth2的PHP客户端库.我的一切工作都很完美,但是,当令牌在3600秒(60分钟)后到期时,我收到一个错误.
我把它设置为访问令牌到期时,它重定向到主页; 像这样:
if($client->isAccessTokenExpired()) {
session_destroy();
header('Location: index.php');
}
Run Code Online (Sandbox Code Playgroud)
工作正常,虽然相当恼人的用户登录并注销60分钟,尝试使用该应用程序.
如何延长会话时间?
我正在使用适用于PHP的Google API客户端库与Gmail API一起下载和处理一些电子邮件.
我收到消息没有任何问题:
$optParamsGet = [];
$optParamsGet['format'] = 'full'; // Display message in payload
$message = $service->users_messages->get('me',$id,$optParamsGet);
$messagePayload = $message->getPayload();
Run Code Online (Sandbox Code Playgroud)
然后我处理getParts()数组并转到第一个附件,这是一个没有名称的.eml文件
[modelData:protected] => Array
(
[headers] => Array
(
[0] => Array
(
[name] => Content-Type
[value] => message/rfc822
)
[1] => Array
(
[name] => Content-Disposition
[value] => attachment; creation-date="Fri, 24 Jul 2015 00:20:48 GMT"; modification-date="Fri, 24 Jul 2015 00:20:48 GMT"
)
)
[body] => Array
(
[attachmentId] => ANGjdJ_TfJlMTssCNackUcQfT...mpppKiT8sSg
[size] => 37099
)
)
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何解码"attachmentId"字符串?我认为这是一个base64编码,但命令
echo base64_decode($parts[1]->body->attachmentId); …Run Code Online (Sandbox Code Playgroud)