这个错误对Youtube API v3.0意味着什么:
A client error occurred: Could not create storage directory: /tmp/Google_Client/00
Run Code Online (Sandbox Code Playgroud)
我在这里的 Google文档中使用了PHP Youtube API .
我有使用Google PHP Client API的PHP代码来使用Drive服务.
<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Drive.php';
const CLIENT_ID = '[MYCLIENTID]';
const SERVICE_ACCOUNT_NAME = '[MYSERVICEACCOUNID]';
// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = './[MYPRIVATEKEY].p12';
// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$client = new Google_Client();
$client->setApplicationName("Google Drive Sample");
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_Auth_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/drive'),
$key) …Run Code Online (Sandbox Code Playgroud) 我的目标是Google Fusion Tables代表我的网络应用用户进行最简单的查询.为此,我在谷歌控制台上创建了一个服务帐户.这是代码:
// Creating a google client
$client = new \Google_Client();
// setting the service acount credentials
$serviceAccountName = 'XXXXX.apps.googleusercontent.com';
$scopes= array(
'https://www.googleapis.com/auth/fusiontables',
'https://www.googleapis.com/auth/fusiontables.readonly',
);
$privateKey=file_get_contents('/path/to/privatekey.p12');
$privateKeyPassword='notasecret'; // the default one when generated in the console
$credential = new \Google_Auth_AssertionCredentials($serviceAccountName,
$scopes, $privateKey, $privateKeyPassword);
// setting assertion credentials
$client->setAssertionCredentials($credential);
$service = new \Google_Service_Fusiontables($client);
$sql = 'select name from XXXXXXXX';
$result = $service->query->sql($sql);
Run Code Online (Sandbox Code Playgroud)
运行此代码后,我收到此错误:
Error refreshing the OAuth2 token, message: '{
"error" : "invalid_grant"
}'
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索了几天,大多数答案都在谈论刷新令牌.我做了这个刷新,但仍然是同样的错误!
有什么想法解决这个问题吗?谢谢
php symfony google-fusion-tables google-api-php-client service-accounts
我正在开发一个与Google Fit API配合使用的PHP应用程序,以收集每日用户的步数.
我希望从"2015年1月15日00:00:00 GMT + 0700"到"2015年1月16日00:00:00 GMT + 0700"获得我的步数. - 首先,我得到了所有的数据源. - 然后,对于数据类型等于"com.google.step_count.delta"的每个数据源,我获取上述时间戳之间的数据集并将返回值一起添加.
我的代码:https://gist.github.com/daitr-gu/472c4f18522172542cca
我的结果:https://gist.github.com/daitr-gu/1a7e11eb483a657bdc8b
我发现,有很多数据源,它们返回不同的值.这些价值观与我在手机上的Google健身应用中看到的价值太大了.
问题:
1.Google健身应用使用哪种数据源来计算步数?
2.为什么数据源的值与Google Fit值有所不同?
3.我如何获得Google Fit值?
我正在尝试使用服务帐户将文件上传到我的Google云端硬盘.当我部署此代码时,我不希望用户授权,我希望他们上传到我的帐户.我通过PHP使用它,下面是我到目前为止的地方.
此代码基于官方文档提供的示例.当我运行php脚本时,我没有错误,我print_r结果变量.它有多个网址,当我使用我创建的相同帐户访问它时,它说我需要请求权限.当我查看我的Google Developers控制台时,它说它收到了请求并成功运行了它.
但是,该文件不会显示在我的Google云端硬盘中.我不确定在服务帐户上查看这些文件的位置,以及如何将此文件存入我的Google云端硬盘.以下是我的代码.
我在某个地方错过了许可,或者我应该以某种方式将服务帐户连接到普通帐户?
DEFINE("TESTFILE", 'testfile-small.txt');
if (!file_exists(TESTFILE)) {
$fh = fopen(TESTFILE, 'w');
fseek($fh, 1024 * 1024);
fwrite($fh, "!", 1);
fclose($fh);
}
// The setup
// Authentication Credentials
$client_id = '<my client id>'; //Client ID
$service_account_name = '<my client email'; //Email Address
$key_file_location = '<path to key>'; //key.p12
// Create the client
$client = new Google_Client();
$client->setApplicationName("IEEE_File_Upload");
$service = new Google_Service_Drive($client);
// Check for token
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
// Get the key
$key = file_get_contents($key_file_location);
// Create …Run Code Online (Sandbox Code Playgroud) php google-api google-drive-api google-api-php-client service-accounts
首先,我是这个话题的新手,所以我希望我的问题不是太愚蠢.
我希望我的网站能够访问Google Analytics指标.我从谷歌跟踪了这个描述的每一步.不幸的是,当我上传服务器上的所有内容并尝试运行测试站点时,我总是收到以下错误消息:
致命错误:未捕获的异常'Exception',带有消息'此库必须通过composer安装或下载完整的软件包.请参阅https://github.com/google/google-api-php-client#installation上的说明 .在/home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php:14堆栈跟踪:#0 /home/users/myftp/dev.mywebsite .com/dashboard/HelloAnalytics.php(8):require_once()#1 /home/users/myftp/dev.mywebsite.com/dashboard/HelloAnalytics.php(104):getService()#2 {main}抛出/第14行的home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php
显然,嵌入Google客户端库存在问题.在错误消息中它说我必须使用Composer,但是在他们说的GitHub文档中,手动下载也没问题.我想最终这应该没有任何区别?我不熟悉作曲家或GitHub,这就是我手动下载它的原因.
我将它上传到服务器上并将其放入HelloAnalytics.php所在的目录中.我通过HelloAnalytics.php解决它
require_once 'google-api-php-client-master/src/Google/autoload.php'
Run Code Online (Sandbox Code Playgroud) 我在使用PHP的谷歌分析API v4上有这个代码.
$eCPM_Adsense = new Google_Service_AnalyticsReporting_Metric();
$eCPM_Adsense->setExpression("ga:adsenseECPM");
$eCPM_Adsense->setAlias("eCPM Adsense");
// Create the Ordering.
$ordering = new Google_Service_AnalyticsReporting_OrderBy();
$ordering->setFieldName("ga:adsenseECPM");
$ordering->setOrderType("VALUE");
$ordering->setSortOrder("DESCENDING");
Run Code Online (Sandbox Code Playgroud)
订购对我不起作用.你能帮助我吗?谢谢
我使用HWIO Bundle for google api,当我收到来自google refreshToken = null的回复为什么?如何刷新令牌
oAuthToken = {HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken} [11]
accessToken = "ya29.Ci8lA1JTu9CB81dOFy-nzszViRgCI2CvvKVrCd0Lq-8I0QR_dIrl-_7RccdGt1Islg"
rawToken = {array} [4]
access_token = "ya29.Ci8lA1JTu9CB81dOFy-nzszViRgCI2CvvKVrCd0Lq-8I0QR_dIrl-_7RccdGt1Islg"
token_type = "Bearer"
expires_in = 3578
id_token = "xxxxx"
refreshToken = null
expiresIn = 3578
createdAt = 1468957368
tokenSecret = null
resourceOwnerName = null
Run Code Online (Sandbox Code Playgroud)
因为在google/apiclient中,"version":"1.1.7"在函数中需要refresh_token
public function getRefreshToken()
{
if (array_key_exists('refresh_token', $this->token)) {
return $this->token['refresh_token'];
} else {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的访问令牌
{"access_token":"ya29.Ci8lA1JTu9CB81dOFy-nzszViRgCI2CvvKVrCd0Lq-8I0QR_dIrl-_7RccdGt1Islg","token_type":"Bearer","expires_in":3578,"id_token":"xxxx","created":1468957368}
没有刷新令牌,因为从谷歌获取refreshToken = null或需要设置null与键刷新令牌或此dos不metter?
$isExpired = $client->isAccessTokenExpired(); // true (bool Returns True if the access_token …Run Code Online (Sandbox Code Playgroud) 我在使用php设置Google API时遇到问题。请参见下面的代码:
$client = new Google_Client();
$client->setApplicationName("MY_APP_NAME");
Run Code Online (Sandbox Code Playgroud)
我必须对“ MY_APP_NAME”使用什么,是像“ com.mycompany.myapp”这样的appId,还是像“我的游戏名”这样的Playstore中应用程序的标题?
对不起,如果这是重复,但我发现的一些关键问题对我没用.我是一个Laravel新手.我正在尝试使用grisub 库https://github.com/google/google-api-php-client和laravel 5.6框架.
我通过运行安装了api:
作曲家需要google/apiclient:^ 2.0
我的composer.json看起来正确,因为它包括:
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"google/apiclient": "^2.2",
"laravel/framework": "5.6.*",
"laravel/tinker": "^1.0"
},
Run Code Online (Sandbox Code Playgroud)
我已经运行了作曲家更新.我可以在供应商的文件夹中看到Google文件夹.
然后github自述文件说添加自动加载器包括.但是,根据我的理解,这不是我们为Laravel做的方式.我发现Google_Client类没有命名空间,所以我不知道如何将它正确添加到app.php文件中.或者在我想要的控制器中使用它.当我尝试在控制器中创建一个新的Google_Client时,它说无法找到它.如果我尝试"使用"它,我不知道在没有命名空间的情况下提供它的路径.
编辑以添加以下某些评论的更多信息:
我运行'composer require google/apiclient:^ 2.0
输出:
vagrant@homestead:~/code/sageAnalytics$ composer require google/apiclient:^2.0 ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 10 installs, 0 updates, 0 removals
- Installing psr/http-message (1.0.1): Loading from cache
- Installing guzzlehttp/psr7 (1.4.2): Loading from cache
- Installing guzzlehttp/promises (v1.3.1): Loading from cache
- Installing guzzlehttp/guzzle …Run Code Online (Sandbox Code Playgroud)