我正在尝试使用最新版本的google-api-php-client获取访问令牌(请查看此https://github.com/google/google-api-php-client),然后我我正在关注此官方文档:https: //developers.google.com/api-client-library/php/guide/aaa_oauth2_web
唯一的区别是我想使用该服务Google_Service_Plus,而不是Google_Service_Urlshortener.
基本上我做这些步骤:
$client指定客户端ID,客户端密钥,开发人员密钥,范围和重定向URI(指向我的localhost Ubuntu 12.04 - PHP 5.3.10).$plus使用Google客户端初始化Google Plus服务$client.$client->createAuthUrl().$_GET['code']用于令牌交换的授权代码.$client->authenticate($_GET['code']);但谷歌服务器返回HTTP 400,我得到了一个Google_Auth_Exception: Error fetching OAuth2 access token, message: 'invalid_request'.这里的流动打破了.
怎么了?
任何帮助将不胜感激.
提前谢谢,
Niccolò.
我正在尝试使用google-api-php-client和gmail-api来允许我的用户验证他们的Gmail帐户并通过我的网站发送电子邮件.我之前提出了一些更通用的问题,并决定通过这个问题向PHPMailer社区寻求帮助.
我使用PHPMailer发送电子邮件.我想知道在发送之前是否可以从我的PHPMailer对象中提取原始rfc822消息.我应该能够在该字符串上执行base64_encode并为我的Google_Service_Gmail_Message设置"raw"属性.
我试图提取我公司在其Google网站站长工具中注册的公司列表.我这样做是使用PHP和PHP API客户端库(https://developers.google.com/api-client-library/php/).我已经把一切都搞定了,除了它给了我一个空数组的事实.我的代码如下,任何帮助将不胜感激.
为客户端ID,帐户等填写适当的值,并且所有内容都进行了相应的身份验证,因为我使用相同的代码来访问books API.
<?php
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS …Run Code Online (Sandbox Code Playgroud) 由于YouTube v2 API已弃用,我需要迁移到v3.
在v2中,我使用了已弃用的ClientLogin(http://bit.ly/v2_ClientLogin_authentification)身份验证方法来验证,然后将用户视频上传到我的YouTube频道.
使用v3,我尝试使用服务帐户进行身份验证,此处使用相同的代码库
PHP Youtube API v3 - 直接上传 - 未经授权的消息
我从API端点收到相同的错误消息:
调用POST时出错https://www.googleapis.com/youtube/v3/videos?part=status%2Csnippet:(401)未经授权
我还通过Google的tokeninfo(https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=[ ACCESS_TOKEN )检查了访问令牌是否有效:
{
"issued_to": "***.apps.googleusercontent.com",
"audience": "***.apps.googleusercontent.com",
"scope": "https://www.googleapis.com/auth/youtube",
"expires_in": 3592,
"access_type": "offline"
}
Run Code Online (Sandbox Code Playgroud)
我发现的所有YouTube示例均基于OAuth2和用户授权.(像这里的这个:http://bit.ly/yt-api-example-videoupload).但这不是我想要的方式:用户不应该看到任何"请授权上传YouTube视频的内容" ,视频应该上传到我的YT频道而不是他们的频道.
如果没有可能使用API服务帐户,你能否告诉我如何使用OAuth2做到这一点?:-)
这是我目前的代码:
/** Config */
$private_key_password = 'notasecret';
$private_key_file = '***.p12';
$applicationName = '***';
$client_secret = '***'; // <--- WHERE IS THAT CLIENT_SECRET COMING FROM? Secret accounts do not have a client secret?
$client_id = '***.apps.googleusercontent.com'; …Run Code Online (Sandbox Code Playgroud) 我觉得这里的帖子很奇怪但是因为SO是Google API支持的唯一官方渠道,我想我需要在这里问一下.
如果您有API,工具使用或其他与软件开发相关的问题,请使用官方google-cloud-storage标记搜索和发布Stack Overflow上的问题.
好的,所以这里.我花了两天时间努力让谷歌存储工作在亚马逊PHP SDK的v3版本(最新版本)上.我无法使用旧版本的SDK,因为我试图坚持使用Laravel 5.1的文件系统,而无需为Google存储编写全新的驱动程序.我相信这符合Google为Google存储广告的精神:
https://cloud.google.com/storage/docs/migrating
在从Amazon S3到Google Cloud Storage的简单迁移中,您可以使用现有工具和库生成经过身份验证的Amazon S3 REST请求,还可以将经过身份验证的请求发送到Google Cloud Storage.本节将介绍您需要对现有工具和库进行的更改.
要设置简单迁移,请执行以下操作:
设置默认的Google项目.
获取开发人员密钥.
在现有工具或库中,进行以下更改:更改请求端点以使用Google云端存储请求端点.使用相应的Google云端存储访问密钥和密钥(统称为Google开发人员密钥)替换Amazon Web Services(AWS)访问和密钥.
而已!此时,您可以开始使用现有工具和库将密钥哈希消息身份验证代码(HMAC)请求发送到Google云端存储.
真是太棒了!让我们尝试使用使用gsutil工作的互操作性凭据.
$client = new S3Client([
'credentials' => [
'key' => 'GOOGxxxxxxxxxxxxxxx',
'secret' => 'ZfcOTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
],
'region' => 'US',
'version' => 'latest',
'endpoint' => 'https://storage.googleapis.com',
]);
try {
$result = $client->putObject(array(
'Bucket' => 'devtest',
'Key' => 'test',
'Body' => 'Hello world'
));
echo $result['ObjectURL'];
} catch (\Aws\S3\Exception\S3Exception $e) {
// The AWS error code (e.g., ) …Run Code Online (Sandbox Code Playgroud) google-app-engine google-api google-cloud-storage google-api-php-client laravel-5
我正在使用Google API Client Library for php,我希望能够在将查询发送到执行之前对其进行验证.Google BigQuery API中是否有任何方法可以验证查询(获取红色框中的文本).
我找不到它.我正在阅读本节https://cloud.google.com/bigquery/docs/reference/v2/jobs/query

正如标题所示,我想以编程方式撤销授予的访问令牌(在PHP中).我在他们的网站上发现了这个,但似乎无法在api客户端库中找到一个功能.有一个干净的库功能吗?
编辑: 正如DaimTo所指出的,有一个名为revokeToken()的函数.所以这段代码适用于PHP(带作曲家):
require_once "vendor/autoload.php";
$client = new Google_Client();
$client->setApplicationName(GOOGLE_APP_NAME);
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->revokeToken($access_token);
Run Code Online (Sandbox Code Playgroud) 我通过Composer(https://packagist.org/packages/google/apiclient)使用Google的客户端API ,我已成功通过身份验证并收到了访问令牌.
我试图在我的驱动器中添加一行到Google表格,但我找不到任何专门针对PHP的相关文档.
这是我到目前为止所得到的:
$service = new Google_Service_Sheets($a4e->google); // my authenticated Google client object
$spreadsheetId = "11I1xNv8cHzBGE7uuZtB9fQzbgrz4z7lIaEADfta60nc";
$range = "Sheet1!A1:E";
$valueRange= new Google_Service_Sheets_ValueRange();
$service->spreadsheets_values->update($spreadsheetId,$range,$valueRange);
Run Code Online (Sandbox Code Playgroud)
这将返回以下错误:
Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "code": 400, "message": "Invalid valueInputOption: INPUT_VALUE_OPTION_UNSPECIFIED", "errors": [ { "message": "Invalid valueInputOption: INPUT_VALUE_OPTION_UNSPECIFIED", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } } ' in /usr/share/nginx/vendor/google/apiclient/src/Google/Http/REST.php
Run Code Online (Sandbox Code Playgroud)
我对" Google_Service_Sheets_ValueRange()"对象的格式以及如何将一行附加到工作表的末尾而不是必须指定特定范围感到困惑.
我非常感谢对这个问题的任何帮助.
试图找到如何发布从PHP谷歌,加上墙上,但有403甚至使用API探险家在得到了
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
Run Code Online (Sandbox Code Playgroud)
我的PHP代码如下:
$client = new \Google_Client();
$client->setApplicationName("Speerit");
$client->setClientId($appId);
$client->setClientSecret($appSecret);
$client->setAccessType("offline"); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->setAccessToken(
json_encode(
array(
'access_token' => $accessToken,
'expires_in' => 3600,
'token_type' => 'Bearer',
)
)
);
$client->setScopes(
array(
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/plus.me",
"https://www.googleapis.com/auth/plus.stream.write",
)
);
$client = $client->authorize();
// create the URL for this user ID
$url = sprintf('https://www.googleapis.com/plusDomains/v1/people/me/activities');
// create your HTTP request …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Google Analytics Reporting API v4 https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php为WordPress创建一个插件
我们需要加载Google API PHP客户端库
require_once __DIR__ . '/vendor/autoload.php';
我已经下载了最新版本的Google API https://github.com/google/google-api-php-client/releases,但是供应商文件夹包含7000多个文件!
我的问题是我在这里做错了什么还是错过了什么?在供应商文件夹中,我可以看到所有的Google服务。如何在WordPress插件中使用较少文件的Google API?我将感谢您对正确方向的任何帮助。
php google-analytics google-api google-analytics-api google-api-php-client