Square Api 用户必须每月登录才能更新令牌?

Square Api user has to login every month to renew token?

我一直在考虑为我正在开发的应用程序使用方形支付 api。通过 API 帮助 (https://docs.connect.squareup.com/basics/oauth/overview) 特别是在 OAuth 概述上,我发现了一些有趣的东西。

Square OAuth access tokens expire after 30 days with a grace period of 15 days. Applications must manually renew expired access tokens within the 15 day grace period.

这当然是预料之中的,因为令牌确实会过期。但是要更新令牌,我很震惊地知道用户必须再次登录才能授权该应用程序。

这是没有意义的事情。我怎么能期望用户每 30 天登录一次呢?我的意思是,这将超过让应用程序为用户自动执行流程的目的。

我查看了令牌更新示例代码,该代码需要一个授权码(从用户登录获得)。

$oauthRequestBody = array(
    'client_id' => $applicationId,
    'client_secret' => $applicationSecret,
    'code' => $authorizationCode,
    # The OAuth token you want to renew.
    'access_token' => $oauthToken,
  );

有人可以确认我的理解是否正确吗? 如果是这种情况.. Square API 对我来说毫无用处。

您的理解并非如此(幸好!)。文档有点偏离,将很快更新(感谢报告!)。

您只需指定要续订的访问令牌。请在此处查看正确信息 https://docs.connect.squareup.com/api/oauth#post-renew

您的访问令牌已过期,请使用刷新令牌更新它

$oauth_api = new \SquareConnect\Api\OAuthApi();
$body = new \SquareConnect\Model\ObtainTokenRequest();
$body->setClientId($client_id);
$body->setClientSecret($client_secret);
$body->setGrantType('refresh_token');
$body->setRefreshToken($refresh_token);
$oauth_api->obtainToken($body);