【发布时间】:2017-03-02 12:15:33
【问题描述】:
我正在尝试从 Google 的身份验证服务器获取 refresh token,以便在使用官方 Google PHP client library 的服务器端身份验证中与 Google Analytics API 一起使用 Service Account Credential。
我可以创建 access token 并使用它,但目前我每次用户进入页面时都会创建一个新令牌。我想减少流量并获取刷新令牌以将其传递给我的 JavaScript 函数。
gapi.analytics.auth.authorize({
serverAuth: {
access_token: accessToken <-refresh token is that even possible?
}
});
我当前的 PHP 代码是:
$client = new \Google_Client();
$client->setApplicationName("Craft CMS Plugin");
$client->setAuthConfig($credentialPath);
$client->setAccessType('offline');
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$client->refreshTokenWithAssertion();
$this->analyticsAccount = new \Google_Service_Analytics($client);
$token = $client->getAccessToken();
$accessToken = $token['access_token'];
但是没有refresh_token。我可以var_dumpeverything,但我只能找到访问令牌。我已经尝试过这个Refresh Token for Google Api Php Client,但它没有用。
你能帮帮我吗?我怎样才能得到一个。 非常感谢
【问题讨论】:
标签: php google-analytics-api google-api-php-client service-accounts