过去好几天我浪费了很多时间 现在我设法获得刷新令牌..我之前无法获得刷新令牌。
我的目的是在没有Google用户登录的情况下同步Google日历数据
我做了什么:
额外的问题:我可以从之前的刷新令牌获得另一个刷新令牌吗?是不是我可以一遍又一遍地获得刷新令牌?
这是我的一些代码:
public function __construct()
{
$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->addScope(Google_Service_Calendar::CALENDAR); // CALENDAR READONLY 는 읽기만 가능
$guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false)));
$client->setHttpClient($guzzleClient);
$client->setAccessType ("offline");
$client->setApprovalPrompt ("force");
$client->setRedirectUri('http://localhost/smart_mirror/GoogleCalendarApi-master/public/api/cal');
$this->client = $client;
}
$refresh_token=$this->client->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken());
$this->client->getAuth()->refreshToken($this->client->getAuth()->getRefreshToken());
$refresh_token=$this->client->getAccessToken();
答案 0 :(得分:0)
访问令牌的生命周期有限。如果您的应用需要访问权限 对于超出单一访问令牌生命周期的Google API,它可以 获取刷新令牌。刷新令牌允许您的应用程序 获得新的访问令牌。
注意:在安全的长期存储中保存刷新令牌并继续 只要它们仍然有效,就使用它们。限制适用于数量 刷新每个客户端 - 用户组合和每个发布的令牌 所有客户的用户,这些限制是不同的。如果你的 应用程序请求足够的刷新令牌来覆盖其中一个 限制,旧的刷新令牌停止工作。
Refreshing an access token (offline access)
如果您的应用需要离线访问Google API,请将API客户端的访问类型设置为离线:
import java.util.*;
import java.lang.*;
public class Server{
private static String ligning = y=3x^3-2x^2+4x-6;
private static String replacedLigning;
private static int i = 1;
static ArrayList xVærdi = new ArrayList();
static ArrayList x2Værdi = new ArrayList();
static ArrayList x3Værdi = new ArrayList();
while(erTal(ligning.substring((ligning.indexOf("x^3")-i),
(ligning.indexOf("x^3")-i+1))) == true){
x3Værdi.add(ligning.substring((ligning.indexOf("x^3")-i),
(ligning.indexOf("x^3")-i+1)));
i++;
}
replacedLigning = ligning.replace("x^3","");
while(erTal(replacedLigning.substring((replacedLigning.indexOf("x^2")-i),(replacedLigning.indexOf("x^2")-i+1))) == true){
x2Værdi.add(replacedLigning.substring((replacedLigning.indexOf("x^2")-i),(replacedLigning.indexOf("x^2")-i+1)));
i++;
}
System.out.println(replacedLigning); //gives: y=3-2x^2+4x-6
replacedLigning = replacedLigning.replace("x^2","");
System.out.println(replacedLigning); //gives y=3-2+4x-6
i=1;
while(erTal(replacedLigning.substring((replacedLigning.indexOf("x")-i),(replacedLigning.indexOf("x")-i+1))) == true){
xVærdi.add(replacedLigning.substring((replacedLigning.indexOf("x")-i),(replacedLigning.indexOf("x")-i+1)));
i++;
}
Collections.reverse(xVærdi);
Collections.reverse(x2Værdi);
Collections.reverse(x3Værdi);
System.out.println(xVærdi); **//Contains nothing: [] should contain [4]**
System.out.println(x2Værdi); **//Contains nothing: [] should contain [-2]**
System.out.println(x3Værdi); **//Contains [4, ., 6, -] should contain [3]**
double xResult = Double.parseDouble(String.join("", xVærdi)); //gets an error, because the arraylist is empty.
double x2Result = Double.parseDouble(String.join("", x2Værdi));
double x3Result = Double.parseDouble(String.join("", x3Værdi));
这是SO post的另一个示例。