从Google照片中获取照片时获取invalid_grant

时间:2018-11-26 13:00:13

标签: codeigniter google-api-php-client google-apis-explorer google-photos google-photos-api

if(isset($access_token) && !empty($access_token)) {
            try {
                $scope = $this->input->get('scope');
               // $scopes = [$scope];

                $client->setAccessToken($access_token);

                    $credentials = array(
                        'client_id' => $config['web']['client_id'],
                        'client_secret' => $config['web']['client_secret'],
                        'refresh_token' => $access_token
                    );

                    $authCredentials = new UserRefreshCredentials($scope, $credentials);

                    // Set up the Photos Library Client that interacts with the API
                    $photosLibraryClient = new PhotosLibraryClient(['credentials' => $authCredentials]);

                    // Iterate over pages of elements
                    $pagedResponse = $photosLibraryClient->listAlbums();
                    print_r($pagedResponse);die;
                    foreach ($pagedResponse->iteratePages() as $page) {
                        foreach ($page as $element) {
                            // doSomethingWith($element);
                        }
                    }


                /*foreach ($response->iterateAllElements() as $album) {
                    // Get some properties of an album
                    $albumId = $album->getId();
                    $title = $album->getTitle();
                    $productUrl = $album->getProductUrl();
                    $coverPhotoBaseUrl = $album->getCoverPhotoBaseUrl();
                    // The cover photo media item id field may be empty
                    $coverPhotoMediaItemId = $album->getCoverPhotoMediaItemId();
                    $isWriteable = $album->getIsWriteable();
                    $totalMediaItems = $album->getTotalMediaItems();
                }*/

            } catch (\Google\ApiCore\ApiException $exception) {
                // Error during album creation
            } catch (\Google\ApiCore\ValidationException $e) {
                // Error during client creation
                echo $exception;
            }
        }

我可以看到$ photosLibraryClient内部的数据,但无法获取数据$ photosLibraryClient-> listAlbums();

即使我可以访问“ access_token”,也不知道为什么我会遇到奇怪的问题,请指导

遇到错误

    Type: GuzzleHttp\Exception\ClientException

    Message: Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response: { "error": "invalid_grant", "error_description": "Bad Request" } 

Please guide thanks in advance!

0 个答案:

没有答案