首页 > 解决方案 > Square 连接 API | 通过 API 生成个人访问令牌

问题描述

我正在使用 Square Dashboard 中的个人访问令牌来使用 Square Connect PHP SDK 创建付款。

一切都很好,现在我在文档中的某个地方读到访问令牌每 30 天过期一次。这意味着我网站上的付款将在 30 天后停止工作?因为我找不到任何 API 来获取新的个人访问令牌。而且我不想每 30 天手动插入一次访问令牌。

        $api_config = new \SquareConnect\Configuration();
        $api_config->setHost($host_url);
        $api_config->setAccessToken($access_token);
        $api_client = new \SquareConnect\ApiClient($api_config);        
        $payments_api = new \SquareConnect\Api\PaymentsApi($api_client);

        $request_body = array (
        "source_id" =>$data['nonce'],
        "amount_money" => array (
        "amount" => $amount,
        "currency" => $currency
        ),
        "shipping_address" => array (
            "address_line_1" => $data['address_1'],
            "address_line_2" => $data['address_2'],
            "postal_code" => $data['postal_code'],
            "country" => $data['country'],
            "first_name"  => $data['first_name'],
            "last_name" => $data['last_name'],
        ),
        "customer_id" => $transaction->user_id,
        "buyer_email_address" => $data['email'],
        "reference_id" => $transaction->id,
        "note" => $note,
        "idempotency_key" => uniqid()
        );

PS:Square API 文档是有史以来最烂的文档!!!

标签: phpwordpresssquare-connectsquare

解决方案


个人访问令牌永不过期。如果您使用OAuth,那么访问令牌确实每 30 天过期一次,并且您将使用带有arefresh_token的获取令牌来生成新的访问令牌。

此外,请随时将您对我们文档的反馈发送给 Square 的开发人员支持团队,以便我们改进它。


推荐阅读