无法在服务器端刷新Google Calendar API的访问令牌 [英] Can't refresh access token for Google Calendar API on server side

查看:107
本文介绍了无法在服务器端刷新Google Calendar API的访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS上的客户端应用程序授权用户并接收访问令牌和刷新令牌,并将其发送到我的服务器,该服务器将其存储在数据库中. 服务器连接到日历并获取事件. 问题是使用刷新令牌不会以任何方式刷新访问令牌,并且会返回此错误:

My client application on iOS authorizes the user and receives the access token and the refresh token and sends it to my server, where it is stored in the database. The server connects to the calendar and get the events. The problem is that the access token is not refreshed in any way using the refresh token and this error is returned:

{ 错误":"unauthorized_client", "error_description":未经授权" }

{ "error": "unauthorized_client", "error_description": "Unauthorized" }

public function sync($token, $expiresIn, $refreshToken, $created)
{

    $client = new Google_Client();
    $client->setApplicationName('Google Calendar Synchroniser');

    $client->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
    $client->setAuthConfig('../client_secret_***************.apps.googleusercontent.com');
    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');

    $client->setAccessToken(json_encode([
        'access_token' => $token, 
        'created' => $created, 
        'expires_in' => $expiresIn, 
        'refresh_token' => $refreshToken
    ], true));



    //create google calendar service
    $service = new Google_Service_Calendar($client);

    //filter for events searching
    $calendarId = 'primary';
        $optParams = array(
            'maxResults' => 10,
            'singleEvents' => true
        );

    //get events
    $results = $service->events->listEvents($calendarId, $optParams);

}

推荐答案

您可以检查unauthorized_client"的SO帖子. 请记住,您必须通过授权/委派您的应用程序,以避免出现此错误.

You can check this related SO post about the response "unauthorized_client". And remember that you must give access to your application in the control panel of your domain by authorizing/delegating your application to avoid this error.

这篇关于无法在服务器端刷新Google Calendar API的访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆