【问题标题】:Google Fitness API in phpphp 中的 Google 健身 API
【发布时间】:2020-01-10 08:22:17
【问题描述】:
     $user = Socialite::driver('google')->user();

        // Set token for the Google API PHP Client
        $google_client_token = [
            'access_token' => $user->token,
            'refresh_token' => $user->refreshToken,
            'expires_in' => $user->expiresIn
        ];

        $client = new Google_Client();
        $client->setApplicationName("Laravel");
        $client->setDeveloperKey(env('GOOGLE_SERVER_KEY'));
        $client->setAccessToken(json_encode($google_client_token));
        $client->setScopes(Google_Service_Fitness::FITNESS_ACTIVITY_READ);

        $fitness_service = new Google_Service_Fitness($client);

        $dataSources = $fitness_service->users_dataSources;
        $dataSets = $fitness_service->users_dataSources_datasets;

        $listDataSources = $dataSources->listUsersDataSources("me");


        dd($dataSets);

我试过这个,但它总是结束给我 “域”:“全球”, “原因”:“权限不足”, "message": "Insufficient Permission: 请求的身份验证范围不足。"

【问题讨论】:

    标签: php laravel google-api google-api-php-client google-fit


    【解决方案1】:

    Users.dataSources: list 需要使用以下范围之一。

    您似乎正在使用列表中的其中一个

    Google_Service_Fitness::FITNESS_ACTIVITY_READ

    我已经测试过,范围确实允许调用该 api,这意味着它不是 API 的问题。

    问题是您可能已经对用户进行了身份验证,然后更改了代码中的范围,而没有重新对请求新范围的用户进行身份验证。您需要重新登录用户

    'approval_prompt' => '强制'

    你需要它弹出并再次请求许可

    您可能必须转到您的谷歌帐户并删除应用程序权限才能重置它remove

    【讨论】:

    • 'approval_prompt' => 'force' 在哪里添加这个??
    • 自过去 72 小时以来我一直在尝试,但没有任何出路。请让我知道如何解决此问题。
    • 是否再次显示请求权限的屏幕?
    • 不,这不是我没有得到任何请求服务权限的屏幕
    • 我什么都看不到
    猜你喜欢
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多