我无法使用我的代码获取刷新令牌.我只能获得我的访问令牌,令牌类型等,我已经按照一些教程,比如access_type=offline输入我的登录URL:
echo "<a href='https://accounts.google.com/o/oauth2/auth?"
. "access_type=offline&client_id=123345555.apps.googleusercontent.com& "
. "scope=https://www.googleapis.com/auth/calendar+https://www.googleapis.com/auth/plus.me&response_type=code& "
. "redirect_uri=http://www.sample.com/sample.php&state=/profile'>Google</a>";
Run Code Online (Sandbox Code Playgroud)
以及我获取访问令牌的字段:
$fields=array(
'code'=> urlencode($authcode),
'client_id'=> urlencode($clientid),
'client_secret'=> urlencode($clientsecret),
'redirect_uri'=> urlencode($redirecturi),
'grant_type'=> 'authorization_code',
);
Run Code Online (Sandbox Code Playgroud)
但是我无法获得refresh_token,只有access_token,token_type,id_token和expires_in.
我正在编写一个PHP应用程序,它应该允许用户将某些事件添加到私人Google日历中.日历由我拥有,我需要一种方法让PHP使用固定凭据与日历API进行通信(每个人都可以使用网站上的表单添加事件,但日历本身不公开).
根据我的阅读,可以在v1 API中使用ClientLogin.但是,在v3 API中,可用选项是OAuth2.0或API密钥.使用API密钥似乎不起作用,因为它只能用于不需要授权的请求,而OAuth似乎也不正确,因为用户不应该访问他们自己的日历,而是我的日历应用程序使用
我考虑以编程方式获取OAuth令牌,但由于OAuth对话框可以使用验证码,因此迟早会中断.
这似乎是一个标准的用例 - 一个允许用户以某种预定义的方式与单个日历交互的Web应用程序 - 但我找不到任何关于如何在v3 API中实现它的文档.谁能帮我?
php google-calendar-api google-api google-api-php-client google-oauth2
我正在使用OAuth2身份验证,我有一个拥有多个用户的CMS,每个用户都有自己的配置文件.我们公司的Google帐户可以访问多个Google Analytics帐户.对于使用CMS的每个用户,我使用不同的用户名连接到Google AnalyticsAPI,每个用户的令牌都保存在数据库数据存储中.问题是,如果一个用户断开连接并撤消其令牌,则使用相同Google帐户的其他任何用户都无法访问Analytics API,这没有任何意义.

编辑:经过进一步调查,我发现当第一个用户进行身份验证时,保存在数据存储中的令牌包含'refresh_roken'和'access_token'.但是,当其他用户进行身份验证时(他们使用相同的Google帐户,但使用不同的Google Analytics帐户),他们的令牌只会包含"access_token".如果其中一个人撤销了他的令牌,他们就会失去联系.
如何阻止这种情况发生并让每个用户都收到自己的refresh_token?
编辑2:
我在数据存储中存储单独的行,每个用户一个.让我澄清一下 - 如果你看一下这个图,想象一个CMS,其中一个CMS用户需要查看"Liz的个人账户"的统计数据,另一个CMS用户需要查看"Liz的团队账户"的统计数据.
两个CMS用户都来自同一家公司,他们都使用相同的Google帐户 - "liz@gmail.com".CMS用户A使用"liz@gmail.com"连接到Analytics API,收到refresh_token并想查看"Liz网站"的统计信息.然后CMS用户B也使用"liz@gmail.com"连接到Analytics API,但现在他不再收到refresh_token,只有access_token - 这是一个问题,因为在access_token之后将再次要求用户连接到期.
当一个用户断开连接时我通常做的是从数据存储中删除令牌并撤销令牌,但是我可能不应该撤销它,是吗?在任何情况下,如果在我的场景中用户A断开连接,这将删除他的数据存储令牌,这意味着我们将不再存储refresh_token,因为用户B首先没有它.
用户帐户图:

c# google-api google-analytics-api google-api-dotnet-client google-oauth2
这个问题类似于Not received Google OAuth refresh token,但我已经按照已access_type='offline'接受解决方案的评论中的建议进行了指定。
我正在编写一个 Django 应用程序来使用 Google API 发送日历邀请,这基本上是对https://developers.google.com/api-client-library/python/auth/web-app 上给出的 Flask 示例的改编,在其中我创建了一个模型GoogleCredentials来将凭据持久存储在数据库中,而不是在会话中。
以下是观点:
import logging
from django.conf import settings
from django.shortcuts import redirect
from django.http import JsonResponse
from django.urls import reverse
from django.contrib.auth.decorators import login_required
import google.oauth2.credentials
import google_auth_oauthlib.flow
import googleapiclient.discovery
from lucy_web.models import GoogleCredentials
logger = logging.getLogger(__name__)
# Client configuration for an OAuth 2.0 web server application
# (cf. https://developers.google.com/identity/protocols/OAuth2WebServer)
# This is constructed from environment variables rather …Run Code Online (Sandbox Code Playgroud) 每当我使用Google One Tap登录 Android 应用程序时,我都会收到一个有效期约为一小时的令牌 ID 。我应该如何获得刷新令牌以避免该令牌过期时每小时登录?我查了官方文档,但没有关于刷新令牌的内容。这是否意味着每次发生这种情况时我们都需要手动登录(并获取新令牌)?
https://developers.google.com/identity/one-tap/android/overview
android google-authentication google-identity google-one-tap
I'm trying implement a photo uploading to Google Drive feature (using the Google Drive API and GIS) into a web app that I'm working on, but can't seem to figure out how to keep a user authenticated for longer than the designated expiry time of the access token (which is 1 hour) without prompting the user or opening a popup.
The sample code provided at https://github.com/googleworkspace/browser-samples/blob/master/drive/quickstart/index.html forces the user to click a "refresh" button to get a new token, but …
我正在尝试使用oauth 2.0来使用gmail smtp.我使用aspose.dll来使用授权URL请求访问令牌.当我得到响应时,我没有获得刷新令牌.因此,如果之前的过期,则无法请求新的访问令牌.所以我想到每次我的应用程序需要获取访问令牌.如果授权代码过期,那么我就无法遵循这种方法.
gmail oauth2的授权代码是否会过期?
我正在开发用于从谷歌分析帐户获取额外数据的模块。为了获得这些数据,谷歌需要 access_token。这是我到目前为止所管理的
if (isset($_GET['code'])) {
// try to get an access token
$code = $_GET['code'];
$url = 'https://accounts.google.com/o/oauth2/token';
$params = array(
"code" => $code,
"client_id" => "559825975819-881lg83vs8feo70v5unqa8kfoijuvfnn.apps.googleusercontent.com",
"client_secret" => "vj4UNNItAJocX4RkNaD_3DQ4",
"redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],
"access_type" => "offline",
"grant_type" => "authorization_code"
);
$ch = curl_init();
curl_setopt($ch, constant("CURLOPT_" . 'URL'), $url);
curl_setopt($ch, constant("CURLOPT_" . 'POST'), true);
curl_setopt($ch, constant("CURLOPT_" . 'POSTFIELDS'), $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$data = (json_decode($output, true));
$access_token_var = $data['access_token'];
echo …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails + Garb Gem(Sija Branch)+ omniauth-google-oauth2 Gem,我可以使用Google AnalyticsAPI成功验证并提取我们的应用在使用用户登录时生成的数据,例如:
Garb::Session.login('USERNAME', '<PASSWORD>')
Run Code Online (Sandbox Code Playgroud)
然后我可以使用Garb连接到我想要的Analytics Profile并从中提取数据并在网页上显示一些图表.一切正常.
但是,我想使用oAuth2对Analytics进行身份验证,这就是为什么我必须从Github安装Garb Gem的Sija分支(它支持oAuth2),我还安装了omniauth-google-oauth2 Gem.现在理论上我应该能够使用以下代码进行身份验证:
Garb::Session.access_token = access_token # an instance of OAuth2::Client
Run Code Online (Sandbox Code Playgroud)
在这一点上,它对我来说有点模糊,我非常感谢一些指导.这是我走了多远:
1)我在Google API控制台中创建了一个项目,并启用了服务下的Analytics API
2)这为我提供了客户端ID和客户端密钥
3)我遇到了这个代码,我可以用上面的ID和Secret填充:
client = OAuth2::Client.new(
GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET,
{
:site => 'https://accounts.google.com',
:authorize_url => '/o/oauth2/auth',
:token_url => '/o/oauth2/token'
})
Run Code Online (Sandbox Code Playgroud)
4)然后是下一段代码:
response = OAuth2::AccessToken.new(
client,
STORED_TOKEN, {
refresh_token: STORED_REFRESH_TOKEN,
expires_at: STORED_EXPIRES_AT
})
Run Code Online (Sandbox Code Playgroud)
5)然后在理论上连接:
Garb::Session.access_token = response
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我没有上面第(4)点中的令牌信息.在我看来,使用oAuth2我需要进行一次"握手"并打印出返回令牌值?也许通过Rails代码打印返回的值,然后将令牌值粘贴到Rails应用程序中的常量中,以便我可以在上面的代码中使用它们?我真的很困惑.正如我之前提到的,使用用户登录身份验证,Web应用程序正常工作.所有Web应用程序正在进行的是使用分析进行身份验证,下拉一些数据并绘制图表.但是由于我不知道如何获得Garb Gem正在寻找的访问令牌,所以我无法将其转换为oAuth2 .我还应该注意,这不是一个有多个用户身份验证的公共网站,这是一个连接到我们自己的Google Analytics数据的CMS网站.
我已经看到了一些方面的部分片段,但没有完全解释或工作的例子.我真的很感激任何指导和帮助这个问题.
提前谢谢了,
JR
ruby-on-rails google-analytics-api access-token oauth-2.0 garb-gem
我使用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) google-api ×4
access-token ×3
php ×3
oauth-2.0 ×2
android ×1
aspose ×1
c# ×1
django ×1
garb-gem ×1
gdata ×1
gmail ×1
gmail-imap ×1
google-oauth ×1
javascript ×1
python ×1
token ×1